From 8060c5bce185deb1e451eec766417cc1549d6f77 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Tue, 17 Jul 2007 09:12:15 +0000 Subject: [PATCH] Routines git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@208 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- editing.inc.php | 29 ++++++++++++++-------------- functions.inc.php | 4 ---- index.php | 2 +- procedure.inc.php | 48 ++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 56 insertions(+), 27 deletions(-) diff --git a/editing.inc.php b/editing.inc.php index 69c7e70e..05e04fdb 100644 --- a/editing.inc.php +++ b/editing.inc.php @@ -81,7 +81,7 @@ function edit_fields($fields, $collations, $type = "TABLE") { global $inout; ?> - + @@ -99,7 +99,7 @@ function edit_fields($fields, $collations, $type = "TABLE") { $i++; ?> - + " />" maxlength="64" /> @@ -133,32 +133,31 @@ for (var i=1; >= i; i++) { result($mysql->query("SHOW CREATE $type " . idf_escape($name)), 2); - preg_match("~\\(($pattern(?:\\s*,$pattern)*)\\)" . ($type == "FUNCTION" ? "\\s*RETURNS\\s+$type_pattern" : "") . "\\s*(.*)~is", $create, $match); + preg_match("~\\(((?:$pattern\\s*,?)*)\\)" . ($type == "FUNCTION" ? "\\s*RETURNS\\s+$type_pattern" : "") . "\\s*(.*)~is", $create, $match); $fields = array(); - preg_match_all("~$pattern~is", $match[1], $matches, PREG_SET_ORDER); + preg_match_all("~$pattern\\s*,?~is", $match[1], $matches, PREG_SET_ORDER); foreach ($matches as $i => $param) { $fields[$i] = array( "field" => str_replace("``", "`", $param[2]) . $param[3], - "type" => $param[4], //! type aliases + "type" => strtolower($param[4]), //! type aliases "length" => preg_replace_callback("~$enum_length~s", 'normalize_enum', $param[5]), "unsigned" => strtolower(preg_replace('~\\s+~', ' ', trim("$param[7] $param[6]"))), - "null" => true, "inout" => strtoupper($param[1]), - //! detect character set + "collation" => strtolower($param[8]), ); } if ($type != "FUNCTION") { - return array("fields" => $fields, "definition" => $match[16]); + return array("fields" => $fields, "definition" => $match[10]); } - $returns = array( - "type" => $match[16], - "length" => preg_replace_callback("~$enum_length~s", 'normalize_enum', $match[17]), - "unsigned" => strtolower(preg_replace('~\\s+~', ' ', trim("$match[19] $match[18]"))), - ); - return array("fields" => $fields, "returns" => $returns, "definition" => $match[20]); + $returns = array("type" => $match[10], "length" => $match[11], "unsigned" => $match[13], "collation" => $match[14]); + return array("fields" => $fields, "returns" => $returns, "definition" => $match[15]); } diff --git a/functions.inc.php b/functions.inc.php index a225aa9d..ec945b00 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -117,10 +117,6 @@ function view($name) { return array("select" => preg_replace('~^(?:[^`]+|`[^`]*`)* AS ~U', '', $mysql->result($mysql->query("SHOW CREATE VIEW " . idf_escape($name)), 1))); } -function normalize_enum($match) { - return "'" . str_replace("'", "''", addcslashes(stripcslashes(str_replace($match[0]{0} . $match[0]{0}, $match[0]{0}, substr($match[0], 1, -1))), '\\')) . "'"; -} - function unique_idf($row, $indexes) { foreach ($indexes as $index) { if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") { diff --git a/index.php b/index.php index 4d03691a..136fb758 100644 --- a/index.php +++ b/index.php @@ -96,7 +96,7 @@ if (isset($_GET["dump"])) { echo "\n"; } $result->free(); - echo '

' . lang('Create procedure') . ' ' . lang('Create function') . "

\n"; + echo '

' . lang('Create procedure') . ' ' . lang('Create function') . "

\n"; } } } diff --git a/procedure.inc.php b/procedure.inc.php index 53d06bd9..3e9d0e87 100644 --- a/procedure.inc.php +++ b/procedure.inc.php @@ -1,15 +1,16 @@ query("DROP $routine " . idf_escape($_GET["procedure"])) && $_POST["drop"]) { redirect(substr($SELF, 0, -1), lang('Routine has been dropped.')); } if (!$_POST["drop"]) { $set = array(); - ksort($_POST["fields"]); - foreach ($_POST["fields"] as $field) { - $set[] = idf_escape($field["field"]) . process_type($field, "CHARACTER SET"); + $fields = array_filter((array) $_POST["fields"], 'strlen'); + ksort($fields); + foreach ($fields as $field) { + $set[] = (in_array($field["inout"], $inout) ? "$field[inout] " : "") . idf_escape($field["field"]) . process_type($field, "CHARACTER SET"); } if ($mysql->query( "CREATE $routine " . idf_escape($_POST["name"]) @@ -17,15 +18,40 @@ if ($_POST && !$error) { . (isset($_GET["function"]) ? " RETURNS" . process_type($_POST["returns"], "CHARACTER SET") : "") . " $_POST[definition]" )) { - redirect(substr($SELF, 0, -1), (strlen($_GET["createp"]) ? lang('Routine has been altered.') : lang('Routine has been created.'))); + redirect(substr($SELF, 0, -1), (strlen($_GET["procedure"]) ? lang('Routine has been altered.') : lang('Routine has been created.'))); } } + $error = $mysql->error; } -$collations = get_vals("SHOW CHARACTER SETS"); +page_header(strlen($_GET["procedure"]) +? (isset($_GET["function"]) ? lang('Alter function') : lang('Alter procedure')) . ": " . htmlspecialchars($_GET["procedure"]) +: (isset($_GET["function"]) ? lang('Create function') : lang('Create procedure')) +); + +$collations = get_vals("SHOW CHARACTER SET"); +if ($_POST) { + $row = $_POST; + $row["fields"] = (array) $row["fields"]; + ksort($row["fields"]); + if (!$_POST["add"]) { + echo "

" . lang('Unable to operate routine') . ": " . htmlspecialchars($error) . "

\n"; + $row["fields"] = array_values($row["fields"]); + } else { + array_splice($row["fields"], key($_POST["add"]), 0, array(array())); + } +} elseif (strlen($_GET["procedure"])) { + $row = routine($_GET["procedure"], $routine); + $row["name"] = $_GET["procedure"]; +} else { + $row = array("fields" => array()); +} ?> + +
- + +
@@ -33,3 +59,11 @@ $collations = get_vals("SHOW CHARACTER SETS"); document.getElementById('form')['returns[type]'].onchange(); +

+

+ +: " maxlength="64" /> + + +

+