From ec6185de993668af5ac079b4a29c06ef19655b26 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Mon, 9 Jul 2007 16:11:34 +0000 Subject: [PATCH] Calls git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@86 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- call.inc.php | 74 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/call.inc.php b/call.inc.php index a61700d4..365378ba 100644 --- a/call.inc.php +++ b/call.inc.php @@ -1,16 +1,47 @@ $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"]); } - $result = mysql_query("CALL " . idf_escape($_GET["call"])); //! params - if ($result === true) { - redirect(substr($SELF, 0, -1), lang('Routine has been called, %d row(s) affected.', mysql_affected_rows())); - } elseif (!$result) { + if (!$match[1] || strcasecmp("in", substr($match[1], 0, 2)) == 0) { + $in[] = $i; + } + $params[$i] = $field; +} +if ($_POST) { + $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); + } + $result = mysql_query((isset($_GET["callf"]) ? "SELECT" : "CALL") . " " . idf_escape($_GET["call"]) . "(" . implode(", ", $call) . ")"); + if (!$result) { $error = mysql_error(); + } elseif ($result === true) { + $message = lang('Routine has been called, %d row(s) affected.', mysql_affected_rows()); + if (!$out) { + redirect(substr($SELF, 0, -1), $message); + } } } @@ -20,16 +51,31 @@ if ($_POST) { if (!$result) { echo "

" . lang('Error during calling') . ": " . htmlspecialchars($error) . "

\n"; } else { - select($result); + if ($result == true) { + echo "

$message

\n"; + } else { + select($result); + } + if ($out) { + select(mysql_query("SELECT " . implode(", ", $out))); + } } } ?> +
\n"; - foreach ($params as $key => $val) { - echo "" . htmlspecialchars($key) . "" . input("param[]", $val["type"]) . "\n"; + foreach ($in as $key) { + $field = $params[$key]; + echo "" . htmlspecialchars($field["field"]) . ""; + $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 "\n"; } echo "\n"; }