Use fields()

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@19 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2007-07-03 07:39:03 +00:00
parent 288bc1ef44
commit 59b05079a6
2 changed files with 19 additions and 25 deletions

View file

@ -36,16 +36,7 @@ if ($_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"]) . "'"));
$row["name"] = $_GET["create"]; $row["name"] = $_GET["create"];
$row["fields"] = array(); $row["fields"] = fields($_GET["create"]);
$result1 = mysql_query("SHOW COLUMNS FROM " . idf_escape($_GET["create"]));
while ($row1 = mysql_fetch_assoc($result1)) {
if (preg_match('~^([^)]*)\\((.*)\\)$~', $row1["Type"], $match)) {
$row1["Type"] = $match[1];
$row1["Length"] = $match[2];
}
$row["fields"][] = $row1;
}
mysql_free_result($result1);
} else { } else {
$row = array("fields" => array()); $row = array("fields" => array());
} }
@ -60,29 +51,29 @@ if ($_POST) {
<table border="0" cellspacing="0" cellpadding="2"> <table border="0" cellspacing="0" cellpadding="2">
<thead><tr><th><?php echo lang('Name'); ?></th><td><?php echo lang('Type'); ?></td><td><?php echo lang('Length'); ?></td><td><?php echo lang('NULL'); ?></td><td><?php echo lang('Auto-increment'); ?></td></tr></thead> <thead><tr><th><?php echo lang('Name'); ?></th><td><?php echo lang('Type'); ?></td><td><?php echo lang('Length'); ?></td><td><?php echo lang('NULL'); ?></td><td><?php echo lang('Auto-increment'); ?></td></tr></thead>
<?php <?php
$i=-1; $i=0;
foreach ($row["fields"] as $i => $field) { 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 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($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="YES"<?php if ($field["Null"] == "YES") { ?> 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>
</tr> </tr>
<?php <?php
$i++;
} }
} }
$i++;
//! JavaScript for next rows //! JavaScript for next rows
?> ?>
<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($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="YES" /></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> <p>

View file

@ -37,12 +37,15 @@ function fields($table) {
$return = array(); $return = array();
$result = mysql_query("SHOW COLUMNS FROM " . idf_escape($table)); $result = mysql_query("SHOW COLUMNS FROM " . idf_escape($table));
while ($row = mysql_fetch_assoc($result)) { while ($row = mysql_fetch_assoc($result)) {
preg_match('~^(.*?)(?:\\((.+)\\))?$~', $row["Type"], $match); preg_match('~^([^(]+)(?:\\((.+)\\))?( unsigned)?$~', $row["Type"], $match);
$return[$row["Field"]] = array( $return[$row["Field"]] = array(
"field" => $row["Field"],
"type" => $match[1], "type" => $match[1],
"length" => $match[2], "length" => $match[2],
"unsigned" => $match[3],
"default" => $row["Default"], "default" => $row["Default"],
"null" => ($row["Null"] != "NO"), "null" => ($row["Null"] != "NO"),
"extra" => $row["Extra"],
); );
} }
mysql_free_result($result); mysql_free_result($result);