Routines
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@208 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
f8d378fa40
commit
8060c5bce1
|
@ -81,7 +81,7 @@ function edit_fields($fields, $collations, $type = "TABLE") {
|
||||||
global $inout;
|
global $inout;
|
||||||
?>
|
?>
|
||||||
<thead><tr>
|
<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>
|
<th><?php echo ($type == "TABLE" ? lang('Column name') : lang('Parameter name')); ?></th>
|
||||||
<td><?php echo lang('Type'); ?></td>
|
<td><?php echo lang('Type'); ?></td>
|
||||||
<td><?php echo lang('Length'); ?></td>
|
<td><?php echo lang('Length'); ?></td>
|
||||||
|
@ -99,7 +99,7 @@ function edit_fields($fields, $collations, $type = "TABLE") {
|
||||||
$i++;
|
$i++;
|
||||||
?>
|
?>
|
||||||
<tr>
|
<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>
|
<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 edit_type("fields[$i]", $field, $collations); ?>
|
||||||
<?php if ($type == "TABLE") { ?>
|
<?php if ($type == "TABLE") { ?>
|
||||||
|
@ -133,32 +133,31 @@ for (var i=1; <?php echo $count; ?> >= i; i++) {
|
||||||
<?php
|
<?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) {
|
function routine($name, $type) {
|
||||||
global $mysql, $enum_length, $inout;
|
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";
|
$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);
|
$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();
|
$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) {
|
foreach ($matches as $i => $param) {
|
||||||
$fields[$i] = array(
|
$fields[$i] = array(
|
||||||
"field" => str_replace("``", "`", $param[2]) . $param[3],
|
"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]),
|
"length" => preg_replace_callback("~$enum_length~s", 'normalize_enum', $param[5]),
|
||||||
"unsigned" => strtolower(preg_replace('~\\s+~', ' ', trim("$param[7] $param[6]"))),
|
"unsigned" => strtolower(preg_replace('~\\s+~', ' ', trim("$param[7] $param[6]"))),
|
||||||
"null" => true,
|
|
||||||
"inout" => strtoupper($param[1]),
|
"inout" => strtoupper($param[1]),
|
||||||
//! detect character set
|
"collation" => strtolower($param[8]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ($type != "FUNCTION") {
|
if ($type != "FUNCTION") {
|
||||||
return array("fields" => $fields, "definition" => $match[16]);
|
return array("fields" => $fields, "definition" => $match[10]);
|
||||||
}
|
}
|
||||||
$returns = array(
|
$returns = array("type" => $match[10], "length" => $match[11], "unsigned" => $match[13], "collation" => $match[14]);
|
||||||
"type" => $match[16],
|
return array("fields" => $fields, "returns" => $returns, "definition" => $match[15]);
|
||||||
"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]);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)));
|
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) {
|
function unique_idf($row, $indexes) {
|
||||||
foreach ($indexes as $index) {
|
foreach ($indexes as $index) {
|
||||||
if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") {
|
if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") {
|
||||||
|
|
|
@ -96,7 +96,7 @@ if (isset($_GET["dump"])) {
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
}
|
}
|
||||||
$result->free();
|
$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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
$routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE");
|
$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"]) {
|
if (strlen($_GET["procedure"]) && $mysql->query("DROP $routine " . idf_escape($_GET["procedure"])) && $_POST["drop"]) {
|
||||||
redirect(substr($SELF, 0, -1), lang('Routine has been dropped.'));
|
redirect(substr($SELF, 0, -1), lang('Routine has been dropped.'));
|
||||||
}
|
}
|
||||||
if (!$_POST["drop"]) {
|
if (!$_POST["drop"]) {
|
||||||
$set = array();
|
$set = array();
|
||||||
ksort($_POST["fields"]);
|
$fields = array_filter((array) $_POST["fields"], 'strlen');
|
||||||
foreach ($_POST["fields"] as $field) {
|
ksort($fields);
|
||||||
$set[] = idf_escape($field["field"]) . process_type($field, "CHARACTER SET");
|
foreach ($fields as $field) {
|
||||||
|
$set[] = (in_array($field["inout"], $inout) ? "$field[inout] " : "") . idf_escape($field["field"]) . process_type($field, "CHARACTER SET");
|
||||||
}
|
}
|
||||||
if ($mysql->query(
|
if ($mysql->query(
|
||||||
"CREATE $routine " . idf_escape($_POST["name"])
|
"CREATE $routine " . idf_escape($_POST["name"])
|
||||||
|
@ -17,15 +18,40 @@ if ($_POST && !$error) {
|
||||||
. (isset($_GET["function"]) ? " RETURNS" . process_type($_POST["returns"], "CHARACTER SET") : "") . "
|
. (isset($_GET["function"]) ? " RETURNS" . process_type($_POST["returns"], "CHARACTER SET") : "") . "
|
||||||
$_POST[definition]"
|
$_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">
|
<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>
|
</table>
|
||||||
<?php echo type_change(count($row["fields"])); ?>
|
<?php echo type_change(count($row["fields"])); ?>
|
||||||
<?php if (isset($_GET["function"])) { ?>
|
<?php if (isset($_GET["function"])) { ?>
|
||||||
|
@ -33,3 +59,11 @@ $collations = get_vals("SHOW CHARACTER SETS");
|
||||||
document.getElementById('form')['returns[type]'].onchange();
|
document.getElementById('form')['returns[type]'].onchange();
|
||||||
</script>
|
</script>
|
||||||
<?php } ?>
|
<?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>
|
||||||
|
|
Loading…
Reference in a new issue