Permalink
Browse files

Routines

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@208 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent f8d378f commit 8060c5bce185deb1e451eec766417cc1549d6f77 jakubvrana committed Jul 17, 2007
Showing with 56 additions and 27 deletions.
  1. +14 −15 editing.inc.php
  2. +0 −4 functions.inc.php
  3. +1 −1 index.php
  4. +41 −7 procedure.inc.php
View
@@ -81,7 +81,7 @@ function edit_fields($fields, $collations, $type = "TABLE") {
global $inout;
?>
<thead><tr>
-<?php if ($type == "PROCEDURE") { ?><td><?php echo lang('In-Out'); ?></td><?php } ?>
+<?php if ($type == "PROCEDURE") { ?><td><?php echo lang('IN-OUT'); ?></td><?php } ?>
<th><?php echo ($type == "TABLE" ? lang('Column name') : lang('Parameter name')); ?></th>
<td><?php echo lang('Type'); ?></td>
<td><?php echo lang('Length'); ?></td>
@@ -99,7 +99,7 @@ function edit_fields($fields, $collations, $type = "TABLE") {
$i++;
?>
<tr>
-<?php if ($type == "PROCEDURE") { ?><td><select name="inout"><?php echo optionlist($inout, $field["inout"]); ?></select></td><?php } ?>
+<?php if ($type == "PROCEDURE") { ?><td><select name="fields[<?php echo $i; ?>][inout]"><?php echo optionlist($inout, $field["inout"]); ?></select></td><?php } ?>
<th><input type="hidden" name="fields[<?php echo $i; ?>][orig]" value="<?php echo htmlspecialchars($field[($_POST ? "orig" : "field")]); ?>" /><input name="fields[<?php echo $i; ?>][field]" value="<?php echo htmlspecialchars($field["field"]); ?>" maxlength="64" /></th>
<?php edit_type("fields[$i]", $field, $collations); ?>
<?php if ($type == "TABLE") { ?>
@@ -133,32 +133,31 @@ function type_change(type) {
<?php
}
+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 routine($name, $type) {
global $mysql, $enum_length, $inout;
- $type_pattern = "([a-z]+)(?:\\s*\\(((?:[^'\")]*|$enum_length)+)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?";
+ $type_pattern = "([a-z]+)(?:\\s*\\(((?:[^'\")]*|$enum_length)+)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s]+)['\"]?)?";
$pattern = "\\s*(" . ($type == "FUNCTION" ? "" : implode("|", $inout)) . ")?\\s*(?:`((?:[^`]+|``)*)`\\s*|\\b(\\S+)\\s+)$type_pattern";
$create = $mysql->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]);
}
View
@@ -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") {
View
@@ -96,7 +96,7 @@
echo "</table>\n";
}
$result->free();
- echo '<p><a href="' . htmlspecialchars($SELF) . 'function=">' . lang('Create procedure') . '</a> <a href="' . htmlspecialchars($SELF) . 'createf=">' . lang('Create function') . "</a></p>\n";
+ echo '<p><a href="' . htmlspecialchars($SELF) . 'procedure=">' . lang('Create procedure') . '</a> <a href="' . htmlspecialchars($SELF) . 'function=">' . lang('Create function') . "</a></p>\n";
}
}
}
View
@@ -1,35 +1,69 @@
<?php
$routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE");
-if ($_POST && !$error) {
+if ($_POST && !$error && !$_POST["add"]) {
if (strlen($_GET["procedure"]) && $mysql->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"])
. " (" . implode(", ", $set) . ")"
. (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 "<p class='error'>" . lang('Unable to operate routine') . ": " . htmlspecialchars($error) . "</p>\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());
+}
?>
+
+<form action="" method="post" id="form">
<table border="0" cellspacing="0" cellpadding="2">
-<tr><th><?php echo lang('Return type'); ?></th><?php echo edit_type("returns", $row["returns"], $collations); ?></tr>
+<?php edit_fields($row["fields"], get_vals("SHOW CHARACTER SET"), $routine); ?>
+<?php if (isset($_GET["function"])) { ?><tr><td><?php echo lang('Return type'); ?></th><?php echo edit_type("returns", $row["returns"], $collations); ?></tr><?php } ?>
</table>
<?php echo type_change(count($row["fields"])); ?>
<?php if (isset($_GET["function"])) { ?>
<script type="text/javascript">
document.getElementById('form')['returns[type]'].onchange();
</script>
<?php } ?>
+<p><textarea name="definition" rows="10" cols="80" style="width: 98%;"><?php echo htmlspecialchars($row["definition"]); ?></textarea></p>
+<p>
+<input type="hidden" name="token" value="<?php echo $token; ?>" />
+<?php echo lang('Name'); ?>: <input name="name" value="<?php echo htmlspecialchars($row["name"]); ?>" maxlength="64" />
+<input type="submit" value="<?php echo lang('Save'); ?>" />
+<?php if (strlen($_GET["procedure"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>" /><?php } ?>
+</p>
+</form>

0 comments on commit 8060c5b

Please sign in to comment.