2007-07-09 07:29:02 +00:00
|
|
|
<?php
|
2007-07-10 13:30:42 +00:00
|
|
|
page_header(lang('Call') . ": " . htmlspecialchars($_GET["call"]));
|
|
|
|
|
2007-07-09 23:13:34 +00:00
|
|
|
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))), '\\')) . "'";
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
|
2007-07-10 18:53:35 +00:00
|
|
|
$pattern = "\\s*(IN|OUT|INOUT)?\\s*(?:`((?:[^`]+|``)*)`\\s*|\\b(\\S+)\\s+)([a-z]+)(?:\\s*\\(((?:[^'\")]*|$enum_length)+)\\))?\\s*(?:zerofill\\s+)?(unsigned)?";
|
2007-07-11 08:24:03 +00:00
|
|
|
$create = $mysql->result($mysql->query("SHOW CREATE " . (isset($_GET["callf"]) ? "FUNCTION" : "PROCEDURE") . " " . idf_escape($_GET["call"])), 2);
|
2007-07-09 16:11:34 +00:00
|
|
|
preg_match("~\\($pattern(?:\\s*,$pattern)*~is", $create, $match);
|
|
|
|
$in = array();
|
|
|
|
$out = array();
|
|
|
|
$params = array();
|
|
|
|
preg_match_all("~$pattern~is", $match[0], $matches, PREG_SET_ORDER);
|
|
|
|
foreach ($matches as $i => $match) {
|
|
|
|
$field = array(
|
|
|
|
"field" => str_replace("``", "`", $match[2]) . $match[3],
|
|
|
|
"type" => $match[4], //! type aliases
|
2007-07-10 18:53:35 +00:00
|
|
|
"length" => preg_replace_callback("~$enum_length~s", 'normalize_enum', $match[5]),
|
2007-07-09 16:11:34 +00:00
|
|
|
"unsigned" => ($match[6] ? "unsigned" : ""), // zerofill ignored
|
|
|
|
"null" => true,
|
|
|
|
);
|
|
|
|
if (strcasecmp("out", substr($match[1], -3)) == 0) {
|
|
|
|
$out[$i] = "@" . idf_escape($field["field"]) . " AS " . idf_escape($field["field"]);
|
|
|
|
}
|
|
|
|
if (!$match[1] || strcasecmp("in", substr($match[1], 0, 2)) == 0) {
|
|
|
|
$in[] = $i;
|
|
|
|
}
|
|
|
|
$params[$i] = $field;
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
|
2007-07-09 07:29:02 +00:00
|
|
|
if ($_POST) {
|
2007-07-09 16:11:34 +00:00
|
|
|
$call = array();
|
|
|
|
foreach ($params as $key => $field) {
|
|
|
|
if (in_array($key, $in)) {
|
|
|
|
$val = process_input($key, $field);
|
2007-07-11 11:04:18 +00:00
|
|
|
if ($val === false) {
|
|
|
|
$val = "''";
|
|
|
|
}
|
2007-07-09 16:11:34 +00:00
|
|
|
if (isset($out[$key])) {
|
2007-07-10 13:30:42 +00:00
|
|
|
$mysql->query("SET @" . idf_escape($field["field"]) . " = " . $val);
|
2007-07-09 16:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$call[] = (isset($out[$key]) ? "@" . idf_escape($field["field"]) : $val);
|
2007-07-09 07:29:02 +00:00
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
$result = $mysql->multi_query((isset($_GET["callf"]) ? "SELECT" : "CALL") . " " . idf_escape($_GET["call"]) . "(" . implode(", ", $call) . ")");
|
2007-07-09 07:29:02 +00:00
|
|
|
if (!$result) {
|
2007-07-10 13:30:42 +00:00
|
|
|
echo "<p class='error'>" . lang('Error during calling') . ": " . htmlspecialchars($mysql->error) . "</p>\n";
|
2007-07-09 07:29:02 +00:00
|
|
|
} else {
|
2007-07-10 13:30:42 +00:00
|
|
|
do {
|
|
|
|
$result = $mysql->store_result();
|
|
|
|
if (is_object($result)) {
|
|
|
|
select($result);
|
|
|
|
} else {
|
|
|
|
echo "<p class='message'>" . lang('Routine has been called, %d row(s) affected.', $mysql->affected_rows) . "</p>\n";
|
|
|
|
}
|
|
|
|
} while ($mysql->next_result());
|
2007-07-09 16:11:34 +00:00
|
|
|
if ($out) {
|
2007-07-10 13:30:42 +00:00
|
|
|
select($mysql->query("SELECT " . implode(", ", $out)));
|
2007-07-09 16:11:34 +00:00
|
|
|
}
|
2007-07-09 07:29:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
2007-07-09 16:11:34 +00:00
|
|
|
|
2007-07-09 07:29:02 +00:00
|
|
|
<form action="" method="post">
|
|
|
|
<?php
|
2007-07-09 16:11:34 +00:00
|
|
|
if ($in) {
|
2007-07-09 07:29:02 +00:00
|
|
|
echo "<table border='0' cellspacing='0' cellpadding='2'>\n";
|
2007-07-09 16:11:34 +00:00
|
|
|
foreach ($in as $key) {
|
|
|
|
$field = $params[$key];
|
|
|
|
echo "<tr><th>" . htmlspecialchars($field["field"]) . "</th><td>";
|
|
|
|
$value = $_POST["fields"][$key];
|
|
|
|
if (strlen($value) && ($field["type"] == "enum" || $field["type"] == "set")) {
|
|
|
|
$value = intval($value);
|
|
|
|
}
|
|
|
|
input($key, $field, $value); // param name can be empty
|
|
|
|
echo "</td></tr>\n";
|
2007-07-09 07:29:02 +00:00
|
|
|
}
|
|
|
|
echo "</table>\n";
|
|
|
|
}
|
|
|
|
?>
|
2007-07-11 21:06:19 +00:00
|
|
|
<p>
|
|
|
|
<input type="hidden" name="token" value="<?php echo $token; ?>" />
|
|
|
|
<input type="submit" value="<?php echo lang('Call'); ?>" />
|
|
|
|
</p>
|
2007-07-09 07:29:02 +00:00
|
|
|
</form>
|