Fixed warnings of alter table

This commit is contained in:
Lionel Laffineur 2023-12-04 22:03:59 +01:00
parent 5f7daff1e0
commit 70b1080775
3 changed files with 37 additions and 22 deletions

View file

@ -22,17 +22,26 @@ if ($TABLE != "") {
}
$row = $_POST;
$row["fields"] = (array) $row["fields"];
if ($row["auto_increment_col"]) {
if (isset($row["fields"])) {
$row["fields"] = (array) $row["fields"];
}
if (isset($row["auto_increment_col"]) && $row["auto_increment_col"]) {
$row["fields"][$row["auto_increment_col"]]["auto_increment"] = true;
}
if ($_POST) {
set_adminer_settings(array("comments" => $_POST["comments"], "defaults" => $_POST["defaults"]));
$array = [];
if (isset($_POST["comments"])) {
$array["comments"] = $_POST["comments"];
}
if (isset($_POST["defaults"])) {
$array["defaults"] = $_POST["defaults"];
}
set_adminer_settings($array);
}
if ($_POST && !process_fields($row["fields"]) && !$error) {
if ($_POST["drop"]) {
if (isset($_POST["drop"]) && $_POST["drop"]) {
queries_redirect(substr(ME, 0, -1), lang('Table has been dropped.'), drop_tables(array($TABLE)));
} else {
$fields = array();
@ -43,10 +52,13 @@ if ($_POST && !process_fields($row["fields"]) && !$error) {
$after = " FIRST";
foreach ($row["fields"] as $key => $field) {
$foreign_key = $foreign_keys[$field["type"]];
$foreign_key = null;
if (isset($field["type"]) && isset($foreign_keys[$field["type"]])) {
$foreign_key = $foreign_keys[$field["type"]];
}
$type_field = ($foreign_key !== null ? $referencable_primary[$foreign_key] : $field); //! can collide with user defined type
if ($field["field"] != "") {
if (!$field["has_default"]) {
if (isset($field["has_default"]) === false || !$field["has_default"]) {
$field["default"] = null;
}
if ($key == $row["auto_increment_col"]) {
@ -123,7 +135,7 @@ page_header(($TABLE != "" ? lang('Alter table') : lang('Create table')), $error,
if (!$_POST) {
$row = array(
"Engine" => $_COOKIE["adminer_engine"],
"Engine" => (isset($_COOKIE["adminer_engine"]) ? $_COOKIE["adminer_engine"] : null),
"fields" => array(array("field" => "", "type" => (isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : "")), "on_update" => "")),
"partition_names" => array(""),
);
@ -132,7 +144,7 @@ if (!$_POST) {
$row = $table_status;
$row["name"] = $TABLE;
$row["fields"] = array();
if (!$_GET["auto_increment"]) { // don't prefill by original Auto_increment for the sake of performance and not reusing deleted ids
if (isset($_GET["auto_increment"]) === false || !$_GET["auto_increment"]) { // don't prefill by original Auto_increment for the sake of performance and not reusing deleted ids
$row["Auto_increment"] = "";
}
foreach ($orig_fields as $field) {

View file

@ -44,7 +44,7 @@ global $adminer, $connection, $driver, $drivers, $edit_functions, $enum_length,
if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility
$_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"];
}
if (!strpos($_SERVER["REQUEST_URI"], '?') && $_SERVER["QUERY_STRING"] != "") { // IIS 7 compatibility
if (isset($_SERVER["QUERY_STRING"]) && !strpos($_SERVER["REQUEST_URI"], '?') && $_SERVER["QUERY_STRING"] != "") { // IIS 7 compatibility
$_SERVER["REQUEST_URI"] .= "?$_SERVER[QUERY_STRING]";
}
if (isset($_SERVER["HTTP_X_FORWARDED_PREFIX"]) && $_SERVER["HTTP_X_FORWARDED_PREFIX"]) {

View file

@ -105,7 +105,7 @@ function referencable_primary($self) {
if ($table_name != $self && fk_support($table)) {
foreach (fields($table_name) as $field) {
if ($field["primary"]) {
if ($return[$table_name]) { // multi column primary key
if (isset($return[$table_name]) && $return[$table_name]) { // multi column primary key
unset($return[$table_name]);
break;
}
@ -121,7 +121,10 @@ function referencable_primary($self) {
* @return array
*/
function adminer_settings() {
parse_str($_COOKIE["adminer_settings"], $settings);
$settings = [];
if (isset($_COOKIE["adminer_settings"])) {
parse_str($_COOKIE["adminer_settings"], $settings);
}
return $settings;
}
@ -131,7 +134,7 @@ function adminer_settings() {
*/
function adminer_setting($key) {
$settings = adminer_settings();
return $settings[$key];
return (isset($settings[$key]) ? $settings[$key] : null);
}
/** Store settings to a cookie
@ -183,10 +186,10 @@ if ($foreign_keys) {
}
echo optionlist(array_merge($extra_types, $structured_types), $type);
?></select><td><input name="<?php echo h($key); ?>[length]" value="<?php echo h($field["length"]); ?>" size="3"<?php echo (!$field["length"] && preg_match('~var(char|binary)$~', $type) ? " class='required'" : ""); //! type="number" with enabled JavaScript ?> aria-labelledby="label-length"><td class="options"><?php
echo "<select name='" . h($key) . "[collation]'" . (preg_match('~(char|text|enum|set)$~', $type) ? "" : " class='hidden'") . '><option value="">(' . lang('collation') . ')' . optionlist($collations, $field["collation"]) . '</select>';
echo ($unsigned ? "<select name='" . h($key) . "[unsigned]'" . (!$type || preg_match(number_type(), $type) ? "" : " class='hidden'") . '><option>' . optionlist($unsigned, $field["unsigned"]) . '</select>' : '');
echo (isset($field['on_update']) ? "<select name='" . h($key) . "[on_update]'" . (preg_match('~timestamp|datetime~', $type) ? "" : " class='hidden'") . '>' . optionlist(array("" => "(" . lang('ON UPDATE') . ")", "CURRENT_TIMESTAMP"), (preg_match('~^CURRENT_TIMESTAMP~i', $field["on_update"]) ? "CURRENT_TIMESTAMP" : $field["on_update"])) . '</select>' : '');
echo ($foreign_keys ? "<select name='" . h($key) . "[on_delete]'" . (preg_match("~`~", $type) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist(explode("|", $on_actions), $field["on_delete"]) . "</select> " : " "); // space for IE
echo "<select name='" . h($key) . "[collation]'" . (preg_match('~(char|text|enum|set)$~', $type) ? "" : " class='hidden'") . '><option value="">(' . lang('collation') . ')' . optionlist($collations, (isset($field["collation"]) ? $field["collation"] : null)) . '</select>';
echo ($unsigned ? "<select name='" . h($key) . "[unsigned]'" . (!$type || preg_match(number_type(), $type) ? "" : " class='hidden'") . '><option>' . optionlist($unsigned, (isset($field["unsigned"]) ? $field["unsigned"] : null)) . '</select>' : '');
echo (isset($field['on_update']) ? "<select name='" . h($key) . "[on_update]'" . (preg_match('~timestamp|datetime~', $type) ? "" : " class='hidden'") . '>' . optionlist(array("" => "(" . lang('ON UPDATE') . ")", "CURRENT_TIMESTAMP"), (preg_match('~^CURRENT_TIMESTAMP~i', (isset($field["on_update"]) ? $field["on_update"] : null)) ? "CURRENT_TIMESTAMP" : $field["on_update"])) . '</select>' : '');
echo ($foreign_keys ? "<select name='" . h($key) . "[on_delete]'" . (preg_match("~`~", $type) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist(explode("|", $on_actions), (isset($field["on_delete"]) ? $field["on_delete"] : null)) . "</select> " : " "); // space for IE
}
/** Filter length value including enums
@ -227,11 +230,11 @@ function process_field($field, $type_field) {
return array(
idf_escape(trim($field["field"])),
process_type($type_field),
($field["null"] ? " NULL" : " NOT NULL"), // NULL for timestamp
(isset($field["null"]) && $field["null"] ? " NULL" : " NOT NULL"), // NULL for timestamp
default_value($field),
(preg_match('~timestamp|datetime~', $field["type"]) && $field["on_update"] ? " ON UPDATE $field[on_update]" : ""),
(support("comment") && $field["comment"] != "" ? " COMMENT " . q($field["comment"]) : ""),
($field["auto_increment"] ? auto_increment() : null),
(isset($field["auto_increment"]) && $field["auto_increment"] ? auto_increment() : null),
);
}
@ -328,7 +331,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = arra
*/
function process_fields(&$fields) {
$offset = 0;
if ($_POST["up"]) {
if (isset($_POST["up"]) && $_POST["up"]) {
$last = 0;
foreach ($fields as $key => $field) {
if (key($_POST["up"]) == $key) {
@ -341,7 +344,7 @@ function process_fields(&$fields) {
}
$offset++;
}
} elseif ($_POST["down"]) {
} elseif (isset($_POST["down"]) && $_POST["down"]) {
$found = false;
foreach ($fields as $key => $field) {
if (isset($field["field"]) && $found) {
@ -354,10 +357,10 @@ function process_fields(&$fields) {
}
$offset++;
}
} elseif ($_POST["add"]) {
} elseif (isset($_POST["add"]) && $_POST["add"]) {
$fields = array_values($fields);
array_splice($fields, key($_POST["add"]), 0, array(array()));
} elseif (!$_POST["drop_col"]) {
} elseif (isset($_POST["drop_col"]) === false || !$_POST["drop_col"]) {
return false;
}
return true;