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
|
||||
$types = array("int"); //!
|
||||
if ($_POST) {
|
||||
$types = types();
|
||||
if ($_POST && !$_POST["add"]) {
|
||||
if ($_POST["drop"]) {
|
||||
$query = "DROP TABLE " . idf_escape($_GET["create"]);
|
||||
$message = lang('Table has been dropped.');
|
||||
|
@ -8,14 +8,15 @@ if ($_POST) {
|
|||
$fields = array();
|
||||
ksort($_POST["fields"]);
|
||||
foreach ($_POST["fields"] as $key => $field) {
|
||||
if (strlen($field["name"]) && in_array($field["type"], $types)) {
|
||||
$length = ($field["length"] ? "(" . intval($field["length"]) . ")" : ""); //! decimal, enum and set lengths
|
||||
$fields[] = idf_escape($field["name"]) . " " . $field["type"] . $length . ($field["not_null"] ? " NOT NULL" : "") . ($field["auto_increment"] ? " AUTO_INCREMENT" : "");
|
||||
if (strlen($field["field"]) && isset($types[$field["type"]])) {
|
||||
$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" : "");
|
||||
} 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"]) . "'" : "");
|
||||
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.');
|
||||
} else {
|
||||
$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";
|
||||
|
||||
if ($_POST) {
|
||||
echo "<p class='error'>" . lang('Unable to operate table') . ": " . htmlspecialchars($error) . "</p>\n";
|
||||
if (!$_POST["add"]) {
|
||||
echo "<p class='error'>" . lang('Unable to operate table') . ": " . htmlspecialchars($error) . "</p>\n";
|
||||
}
|
||||
$row = $_POST;
|
||||
} elseif (strlen($_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 {
|
||||
$row = array("fields" => array());
|
||||
}
|
||||
//! collate columns, references, indexes, unsigned, default
|
||||
//! collate columns, references, indexes, unsigned, zerofill, default
|
||||
?>
|
||||
<form action="" method="post">
|
||||
<p>
|
||||
|
@ -56,8 +59,8 @@ foreach ($row["fields"] as $field) {
|
|||
if (strlen($field["field"])) {
|
||||
?>
|
||||
<tr>
|
||||
<th><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>
|
||||
<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(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 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>
|
||||
|
@ -70,12 +73,13 @@ foreach ($row["fields"] as $field) {
|
|||
?>
|
||||
<tr>
|
||||
<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 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>
|
||||
</tr>
|
||||
</table>
|
||||
<p><input type="submit" name="add" value="<?php echo lang('Add row'); ?>" /></p>
|
||||
<p>
|
||||
<input type="submit" value="<?php echo lang('Save'); ?>" />
|
||||
<?php if (strlen($_GET["create"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>" /><?php } ?>
|
||||
|
|
Loading…
Reference in a new issue