Alter columns
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@23 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
ccadcbec33
commit
b9e08622ad
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
$types = array("int"); //!
|
$types = types();
|
||||||
if ($_POST) {
|
if ($_POST && !$_POST["add"]) {
|
||||||
if ($_POST["drop"]) {
|
if ($_POST["drop"]) {
|
||||||
$query = "DROP TABLE " . idf_escape($_GET["create"]);
|
$query = "DROP TABLE " . idf_escape($_GET["create"]);
|
||||||
$message = lang('Table has been dropped.');
|
$message = lang('Table has been dropped.');
|
||||||
|
@ -8,14 +8,15 @@ if ($_POST) {
|
||||||
$fields = array();
|
$fields = array();
|
||||||
ksort($_POST["fields"]);
|
ksort($_POST["fields"]);
|
||||||
foreach ($_POST["fields"] as $key => $field) {
|
foreach ($_POST["fields"] as $key => $field) {
|
||||||
if (strlen($field["name"]) && in_array($field["type"], $types)) {
|
if (strlen($field["field"]) && isset($types[$field["type"]])) {
|
||||||
$length = ($field["length"] ? "(" . intval($field["length"]) . ")" : ""); //! decimal, enum and set lengths
|
$fields[] = (!strlen($_GET["create"]) ? "" : (strlen($field["orig"]) ? "CHANGE " . idf_escape($field["orig"]) . " " : "ADD ")) . idf_escape($field["field"]) . " $field[type]" . ($field["length"] ? "($field[length])" : "") . ($field["not_null"] ? " NOT NULL" : "") . ($field["auto_increment"] ? " AUTO_INCREMENT" : "");
|
||||||
$fields[] = idf_escape($field["name"]) . " " . $field["type"] . $length . ($field["not_null"] ? " NOT NULL" : "") . ($field["auto_increment"] ? " AUTO_INCREMENT" : "");
|
} elseif (strlen($field["orig"])) {
|
||||||
|
$fields[] = "DROP " . idf_escape($field["orig"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$status = ($_POST["Engine"] ? " ENGINE='" . mysql_real_escape_string($_POST["Engine"]) . "'" : "") . ($_POST["Collation"] ? " COLLATE '" . mysql_real_escape_string($_POST["Collation"]) . "'" : "");
|
$status = ($_POST["Engine"] ? " ENGINE='" . mysql_real_escape_string($_POST["Engine"]) . "'" : "") . ($_POST["Collation"] ? " COLLATE '" . mysql_real_escape_string($_POST["Collation"]) . "'" : "");
|
||||||
if (strlen($_GET["create"])) {
|
if (strlen($_GET["create"])) {
|
||||||
$query = "ALTER TABLE " . idf_escape($_GET["create"]) . " RENAME TO " . idf_escape($_POST["name"]) . ", $status";
|
$query = "ALTER TABLE " . idf_escape($_GET["create"]) . " " . implode(", ", $fields) . ", RENAME TO " . idf_escape($_POST["name"]) . ", $status";
|
||||||
$message = lang('Table has been altered.');
|
$message = lang('Table has been altered.');
|
||||||
} else {
|
} else {
|
||||||
$query = "CREATE TABLE " . idf_escape($_POST["name"]) . " (" . implode(", ", $fields) . ")$status";
|
$query = "CREATE TABLE " . idf_escape($_POST["name"]) . " (" . implode(", ", $fields) . ")$status";
|
||||||
|
@ -31,7 +32,9 @@ page_header(strlen($_GET["create"]) ? lang('Alter table') . ': ' . htmlspecialch
|
||||||
echo "<h2>" . (strlen($_GET["create"]) ? lang('Alter table') . ': ' . htmlspecialchars($_GET["create"]) : lang('Create table')) . "</h2>\n";
|
echo "<h2>" . (strlen($_GET["create"]) ? lang('Alter table') . ': ' . htmlspecialchars($_GET["create"]) : lang('Create table')) . "</h2>\n";
|
||||||
|
|
||||||
if ($_POST) {
|
if ($_POST) {
|
||||||
|
if (!$_POST["add"]) {
|
||||||
echo "<p class='error'>" . lang('Unable to operate table') . ": " . htmlspecialchars($error) . "</p>\n";
|
echo "<p class='error'>" . lang('Unable to operate table') . ": " . htmlspecialchars($error) . "</p>\n";
|
||||||
|
}
|
||||||
$row = $_POST;
|
$row = $_POST;
|
||||||
} elseif (strlen($_GET["create"])) {
|
} elseif (strlen($_GET["create"])) {
|
||||||
$row = mysql_fetch_assoc(mysql_query("SHOW TABLE STATUS LIKE '" . mysql_real_escape_string($_GET["create"]) . "'"));
|
$row = mysql_fetch_assoc(mysql_query("SHOW TABLE STATUS LIKE '" . mysql_real_escape_string($_GET["create"]) . "'"));
|
||||||
|
@ -40,7 +43,7 @@ if ($_POST) {
|
||||||
} else {
|
} else {
|
||||||
$row = array("fields" => array());
|
$row = array("fields" => array());
|
||||||
}
|
}
|
||||||
//! collate columns, references, indexes, unsigned, default
|
//! collate columns, references, indexes, unsigned, zerofill, default
|
||||||
?>
|
?>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<p>
|
<p>
|
||||||
|
@ -56,8 +59,8 @@ foreach ($row["fields"] as $field) {
|
||||||
if (strlen($field["field"])) {
|
if (strlen($field["field"])) {
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<th><input name="fields[<?php echo $i; ?>][field]" value="<?php echo htmlspecialchars($field["field"]); ?>" maxlength="64" /></th>
|
<th><input type="hidden" name="fields[<?php echo $i; ?>][orig]" value="<?php echo htmlspecialchars($field["field"]); ?>" /><input name="fields[<?php echo $i; ?>][field]" value="<?php echo htmlspecialchars($field["field"]); ?>" maxlength="64" /></th>
|
||||||
<td><select name="fields[<?php echo $i; ?>][type]"><?php echo optionlist($types, $field["type"], "not_vals"); ?></select></td>
|
<td><select name="fields[<?php echo $i; ?>][type]"><?php echo optionlist(array_keys($types), $field["type"], "not_vals"); ?></select></td>
|
||||||
<td><input name="fields[<?php echo $i; ?>][length]" value="<?php echo htmlspecialchars($field["length"]); ?>" size="3" /></td>
|
<td><input name="fields[<?php echo $i; ?>][length]" value="<?php echo htmlspecialchars($field["length"]); ?>" size="3" /></td>
|
||||||
<td><input type="checkbox" name="fields[<?php echo $i; ?>][null]" value="1"<?php if ($field["null"]) { ?> checked="checked"<?php } ?> /></td>
|
<td><input type="checkbox" name="fields[<?php echo $i; ?>][null]" value="1"<?php if ($field["null"]) { ?> checked="checked"<?php } ?> /></td>
|
||||||
<td><input type="checkbox" name="fields[<?php echo $i; ?>][extra]" value="auto_increment"<?php if ($field["extra"] == "auto_increment") { ?> checked="checked"<?php } ?> /></td>
|
<td><input type="checkbox" name="fields[<?php echo $i; ?>][extra]" value="auto_increment"<?php if ($field["extra"] == "auto_increment") { ?> checked="checked"<?php } ?> /></td>
|
||||||
|
@ -70,12 +73,13 @@ foreach ($row["fields"] as $field) {
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<th><input name="fields[<?php echo $i; ?>][field]" maxlength="64" /></th>
|
<th><input name="fields[<?php echo $i; ?>][field]" maxlength="64" /></th>
|
||||||
<td><select name="fields[<?php echo $i; ?>][type]"><?php echo optionlist($types, array(), "not_vals"); ?></select></td>
|
<td><select name="fields[<?php echo $i; ?>][type]"><?php echo optionlist(array_keys($types), array(), "not_vals"); ?></select></td>
|
||||||
<td><input name="fields[<?php echo $i; ?>][length]" size="3" /></td>
|
<td><input name="fields[<?php echo $i; ?>][length]" size="3" /></td>
|
||||||
<td><input type="checkbox" name="fields[<?php echo $i; ?>][null]" value="1" /></td>
|
<td><input type="checkbox" name="fields[<?php echo $i; ?>][null]" value="1" /></td>
|
||||||
<td><input type="checkbox" name="fields[<?php echo $i; ?>][extra]" value="auto_increment" /></td>
|
<td><input type="checkbox" name="fields[<?php echo $i; ?>][extra]" value="auto_increment" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
<p><input type="submit" name="add" value="<?php echo lang('Add row'); ?>" /></p>
|
||||||
<p>
|
<p>
|
||||||
<input type="submit" value="<?php echo lang('Save'); ?>" />
|
<input type="submit" value="<?php echo lang('Save'); ?>" />
|
||||||
<?php if (strlen($_GET["create"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>" /><?php } ?>
|
<?php if (strlen($_GET["create"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>" /><?php } ?>
|
||||||
|
|
Loading…
Reference in a new issue