Example #1
0
                    $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 ? " (" . 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_adminer_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" : ""))), "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"]);
                foreach (array_filter($_POST["partition_names"]) as $key => $val) {
                    $value = $_POST["partition_values"][$key];
                    $partitions[] = "\nPARTITION " . idf_escape($val) . " VALUES " . ($_POST["partition_by"] == 'RANGE' ? "LESS THAN" : "IN") . ($value != "" ? " ({$value})" : " MAXVALUE");
                    //! SQL injection
                }
            }
            $partitioning .= "\nPARTITION BY {$_POST['partition_by']}({$_POST['partition']})" . ($partitions ? " (" . implode(",", $partitions) . "\n)" : ($_POST["partitions"] ? " PARTITIONS " . +$_POST["partitions"] : ""));
        } elseif ($TABLE != "" && support("partitioning")) {
            $partitioning .= "\nREMOVE PARTITIONING";
        }
        $message = lang('Table has been altered.');
        if ($TABLE == "") {
            cookie("adminer_engine", $_POST["Engine"]);
            $message = lang('Table has been created.');
        }
        queries_redirect(ME . "table=" . urlencode($_POST["name"]), $message, alter_table($TABLE, $_POST["name"], $fields, $foreign, $_POST["Comment"], $_POST["Engine"] && $_POST["Engine"] != $orig_status["Engine"] ? $_POST["Engine"] : "", $_POST["Collation"] && $_POST["Collation"] != $orig_status["Collation"] ? $_POST["Collation"] : "", $_POST["Auto_increment"] != "" ? +$_POST["Auto_increment"] : "", $partitioning));
    }
}
page_header($TABLE != "" ? lang('Alter table') : lang('Create table'), $error, array("table" => $TABLE), $TABLE);
$row = array("Engine" => $_COOKIE["adminer_engine"], "fields" => array(array("field" => "", "type" => isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : ""))), "partition_names" => array(""));
if ($_POST) {
    $row = $_POST;
    if ($row["auto_increment_col"]) {
        $row["fields"][$row["auto_increment_col"]]["auto_increment"] = true;
    }
    process_fields($row["fields"]);
} elseif ($TABLE != "") {
    $row = $orig_status;
    $row["name"] = $TABLE;
    $row["fields"] = array();
    if (!$_GET["auto_increment"]) {
Example #3
0
                    $value = $_POST["partition_values"][$key];
                    $partitions[] = "\nPARTITION " . idf_escape($val) . " VALUES " . ($_POST["partition_by"] == 'RANGE' ? "LESS THAN" : "IN") . ($value != "" ? " ({$value})" : " MAXVALUE");
                    //! SQL injection
                }
            }
            $partitioning .= "\nPARTITION BY {$_POST['partition_by']}({$_POST['partition']})" . ($partitions ? " (" . implode(",", $partitions) . "\n)" : ($_POST["partitions"] ? " PARTITIONS " . +$_POST["partitions"] : ""));
        } elseif (support("partitioning") && ereg("partitioned", $orig_status["Create_options"])) {
            $partitioning .= "\nREMOVE PARTITIONING";
        }
        $message = lang('Table has been altered.');
        if ($TABLE == "") {
            cookie("adminer_engine", $_POST["Engine"]);
            $message = lang('Table has been created.');
        }
        $name = trim($_POST["name"]);
        queries_redirect(ME . "table=" . urlencode($name), $message, alter_table($TABLE, $name, $jush == "sqlite" && ($use_all_fields || $foreign) ? $all_fields : $fields, $foreign, $_POST["Comment"], $_POST["Engine"] && $_POST["Engine"] != $orig_status["Engine"] ? $_POST["Engine"] : "", $_POST["Collation"] && $_POST["Collation"] != $orig_status["Collation"] ? $_POST["Collation"] : "", $_POST["Auto_increment"] != "" ? +$_POST["Auto_increment"] : "", $partitioning));
    }
}
page_header($TABLE != "" ? lang('Alter table') : lang('Create table'), $error, array("table" => $TABLE), $TABLE);
$row = array("Engine" => $_COOKIE["adminer_engine"], "fields" => array(array("field" => "", "type" => isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : ""))), "partition_names" => array(""));
if ($_POST) {
    $row = $_POST;
    if ($row["auto_increment_col"]) {
        $row["fields"][$row["auto_increment_col"]]["auto_increment"] = true;
    }
    process_fields($row["fields"]);
} elseif ($TABLE != "") {
    $row = $orig_status;
    $row["name"] = $TABLE;
    $row["fields"] = array();
    if (!$_GET["auto_increment"]) {
    $table_name = (string) $table['name'];
    $sql = "PRAGMA table_info(" . $table_name . ")";
    $fieldsquery = $dbconnnew->query($sql);
    $table_fields = $fieldsquery->fetchAll(PDO::FETCH_ASSOC);
    foreach ($table_fields as $table_field) {
        $tablenew[$table_name]['fields'][$table_field['name']] = $table_field;
    }
}
$sql = array();
foreach ($tablenew as $table_name => $table_parts) {
    if (!isset($tableold[$table_name])) {
        $sql[] = create_table($table_name, $table_parts);
    } else {
        foreach ($table_parts['fields'] as $field => $value) {
            if (!isset($tableold[$table_name]['fields'][$field])) {
                $sql[] = alter_table($table_name, $table_parts, $field);
            }
        }
    }
}
foreach ($sql as $sql_command) {
    $command = $dbconnold->query($sql_command);
}
function create_table($table_name, $table_parts)
{
    $body = "";
    $body .= "CREATE TABLE " . $table_name . " (";
    $columns = array();
    $i = 0;
    foreach ($table_parts['fields'] as $field => $value) {
        $columns[$i] = $field . " " . $value['type'] . " ";