$field) { $foreign_keys[str_replace("`", "``", $table_name) . "`" . str_replace("`", "``", $field["field"])] = $table_name; // not idf_escape() - used in JS } $orig_fields = array(); $table_status = array(); if ($TABLE != "") { $orig_fields = fields($TABLE); $table_status = table_status($TABLE); if (!$table_status) { $error = lang('No tables.'); } } $row = $_POST; $row["fields"] = (array) $row["fields"]; if ($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"])); } if ($_POST && !process_fields($row["fields"]) && !$error) { if ($_POST["drop"]) { queries_redirect(substr(ME, 0, -1), lang('Table has been dropped.'), drop_tables(array($TABLE))); } else { $fields = array(); $all_fields = array(); $use_all_fields = false; $foreign = array(); $orig_field = reset($orig_fields); $after = " FIRST"; foreach ($row["fields"] as $key => $field) { $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"]) { $field["default"] = null; } if ($key == $row["auto_increment_col"]) { $field["auto_increment"] = true; } $process_field = process_field($field, $type_field); $all_fields[] = array($field["orig"], $process_field, $after); if (!$orig_field || $process_field != process_field($orig_field, $orig_field)) { $fields[] = array($field["orig"], $process_field, $after); if ($field["orig"] != "" || $after) { $use_all_fields = true; } } if ($foreign_key !== null) { $foreign[idf_escape($field["field"])] = ($TABLE != "" && $jush != "sqlite" ? "ADD" : " ") . format_foreign_key(array( 'table' => $foreign_keys[$field["type"]], 'source' => array($field["field"]), 'target' => array($type_field["field"]), 'on_delete' => $field["on_delete"], )); } $after = " AFTER " . idf_escape($field["field"]); } elseif ($field["orig"] != "") { $use_all_fields = true; $fields[] = array($field["orig"]); } if ($field["orig"] != "") { $orig_field = next($orig_fields); if (!$orig_field) { $after = ""; } } } $partitioning = ""; if ($partition_by[$row["partition_by"]]) { $partitions = array(); if ($row["partition_by"] == 'RANGE' || $row["partition_by"] == 'LIST') { foreach (array_filter($row["partition_names"]) as $key => $val) { $value = $row["partition_values"][$key]; $partitions[] = "\n PARTITION " . idf_escape($val) . " VALUES " . ($row["partition_by"] == 'RANGE' ? "LESS THAN" : "IN") . ($value != "" ? " ($value)" : " MAXVALUE"); //! SQL injection } } $partitioning .= "\nPARTITION BY $row[partition_by]($row[partition])" . ($partitions // $row["partition"] can be expression, not only column ? " (" . implode(",", $partitions) . "\n)" : ($row["partitions"] ? " PARTITIONS " . (+$row["partitions"]) : "") ); } elseif (support("partitioning") && preg_match("~partitioned~", $table_status["Create_options"])) { $partitioning .= "\nREMOVE PARTITIONING"; } $message = lang('Table has been altered.'); if ($TABLE == "") { cookie("adminer_engine", $row["Engine"]); $message = lang('Table has been created.'); } $name = trim($row["name"]); queries_redirect(ME . (support("table") ? "table=" : "select=") . urlencode($name), $message, alter_table( $TABLE, $name, ($jush == "sqlite" && ($use_all_fields || $foreign) ? $all_fields : $fields), $foreign, ($row["Comment"] != $table_status["Comment"] ? $row["Comment"] : null), ($row["Engine"] && $row["Engine"] != $table_status["Engine"] ? $row["Engine"] : ""), ($row["Collation"] && $row["Collation"] != $table_status["Collation"] ? $row["Collation"] : ""), ($row["Auto_increment"] != "" ? number($row["Auto_increment"]) : ""), $partitioning )); } } page_header(($TABLE != "" ? lang('Alter table') : lang('Create table')), $error, array("table" => $TABLE), h($TABLE)); if (!$_POST) { $row = array( "Engine" => $_COOKIE["adminer_engine"], "fields" => array(array("field" => "", "type" => (isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : "")), "on_update" => "")), "partition_names" => array(""), ); if ($TABLE != "") { $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 $row["Auto_increment"] = ""; } foreach ($orig_fields as $field) { $field["has_default"] = isset($field["default"]); $row["fields"][] = $field; } if (support("partitioning")) { $from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . q(DB) . " AND TABLE_NAME = " . q($TABLE); $result = $connection->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1"); list($row["partition_by"], $row["partitions"], $row["partition"]) = $result->fetch_row(); $partitions = get_key_vals("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $from AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION"); $partitions[""] = ""; $row["partition_names"] = array_keys($partitions); $row["partition_values"] = array_values($partitions); } } } $collations = collations(); $engines = engines(); // case of engine may differ foreach ($engines as $engine) { if (!strcasecmp($engine, $row["Engine"])) { $row["Engine"] = $engine; break; } } ?>

: " autocapitalize="off"> " . optionlist(array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]) . "" . on_help("getTarget(event).value", 1) . script("qsl('select').onchange = helpClose;") : ""); ?> "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?>

: "> " . h($row["Comment"]) . "" : '' ) : '') ; ?>

" . optionlist(array("" => "") + $partition_by, $row["partition_by"]) . "" . on_help("getTarget(event).value.replace(/./, 'PARTITION BY \$&')", 1) . script("qsl('select').onchange = partitionByChange;"); ?> (">) : " value=""> > $val) { echo ''; echo '