2007-07-09 07:29:02 +00:00
|
|
|
<?php
|
2007-07-09 16:11:34 +00:00
|
|
|
$length = '(?:[^\'")]*|\'(?:[^\\\\\']*|\\.)+\'|"(?:[^\\\\\"]*|\\.)+")+';
|
|
|
|
$pattern = "\\s*(IN|OUT|INOUT)?(?:\\s*`((?:[^`]*|``)+)`\\s*|\\s+(\\S+)\\s+)([a-z]+)(?:\\s*\\(($length)\\))?\\s*(?:zerofill\\s+)?(unsigned)?";
|
|
|
|
$create = mysql_result(mysql_query("SHOW CREATE " . (isset($_GET["callf"]) ? "FUNCTION" : "PROCEDURE") . " " . idf_escape($_GET["call"])), 0, 2);
|
|
|
|
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
|
|
|
|
"length" => $match[5], //! replace \' by '', replace "" by ''
|
|
|
|
"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-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);
|
|
|
|
if (isset($out[$key])) {
|
|
|
|
mysql_query("SET @" . idf_escape($field["field"]) . " = " . $val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$call[] = (isset($out[$key]) ? "@" . idf_escape($field["field"]) : $val);
|
2007-07-09 07:29:02 +00:00
|
|
|
}
|
2007-07-09 16:11:34 +00:00
|
|
|
$result = mysql_query((isset($_GET["callf"]) ? "SELECT" : "CALL") . " " . idf_escape($_GET["call"]) . "(" . implode(", ", $call) . ")");
|
|
|
|
if (!$result) {
|
2007-07-09 07:29:02 +00:00
|
|
|
$error = mysql_error();
|
2007-07-09 16:11:34 +00:00
|
|
|
} elseif ($result === true) {
|
|
|
|
$message = lang('Routine has been called, %d row(s) affected.', mysql_affected_rows());
|
|
|
|
if (!$out) {
|
|
|
|
redirect(substr($SELF, 0, -1), $message);
|
|
|
|
}
|
2007-07-09 07:29:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
page_header(lang('Call') . ": " . htmlspecialchars($_GET["call"]));
|
|
|
|
|
|
|
|
if ($_POST) {
|
|
|
|
if (!$result) {
|
|
|
|
echo "<p class='error'>" . lang('Error during calling') . ": " . htmlspecialchars($error) . "</p>\n";
|
|
|
|
} else {
|
2007-07-09 16:11:34 +00:00
|
|
|
if ($result == true) {
|
|
|
|
echo "<p class='message'>$message</p>\n";
|
|
|
|
} else {
|
|
|
|
select($result);
|
|
|
|
}
|
|
|
|
if ($out) {
|
|
|
|
select(mysql_query("SELECT " . implode(", ", $out)));
|
|
|
|
}
|
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";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
<p><input type="hidden" name="token" value="<?php echo $token; ?>" /><input type="submit" value="<?php echo lang('Call'); ?>" /></p>
|
|
|
|
</form>
|