From 59b05079a66a8fe4854e038a936aaa7a250591fd Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Tue, 3 Jul 2007 07:39:03 +0000 Subject: [PATCH] Use fields() git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@19 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- create.inc.php | 39 +++++++++++++++------------------------ functions.inc.php | 5 ++++- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/create.inc.php b/create.inc.php index f6580fbf..723fbbad 100644 --- a/create.inc.php +++ b/create.inc.php @@ -36,16 +36,7 @@ if ($_POST) { } elseif (strlen($_GET["create"])) { $row = mysql_fetch_assoc(mysql_query("SHOW TABLE STATUS LIKE '" . mysql_real_escape_string($_GET["create"]) . "'")); $row["name"] = $_GET["create"]; - $row["fields"] = array(); - $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); + $row["fields"] = fields($_GET["create"]); } else { $row = array("fields" => array()); } @@ -60,29 +51,29 @@ if ($_POST) { $field) { - if (strlen($field["Field"])) { +$i=0; +foreach ($row["fields"] as $field) { + if (strlen($field["field"])) { ?> - - - - - + + + + + - - - - - + + + + +
" maxlength="64" />" size="3" /> checked="checked" /> checked="checked" />" maxlength="64" />" size="3" /> checked="checked" /> checked="checked" />

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