]> git.joonet.de Git - adminer.git/commitdiff
Routines
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 17 Jul 2007 09:12:15 +0000 (09:12 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 17 Jul 2007 09:12:15 +0000 (09:12 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@208 7c3ca157-0c34-0410-bff1-cbf682f78f5c

editing.inc.php
functions.inc.php
index.php
procedure.inc.php

index 69c7e70eb6af58eb87e84bc7461b0c031e19f016..05e04fdbef5bf24c30714c9be7638932d7635f97 100644 (file)
@@ -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 @@ for (var i=1; <?php echo $count; ?> >= i; i++) {
 <?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]);
 }
index a225aa9d0fbbce58bb3f8fdcfd46ebcbd9e2551c..ec945b00bedbab141194824163a479cdcbb20370 100644 (file)
@@ -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") {
index 4d03691adcbbff92ad307a76a60f4d18c4677708..136fb758ef951202e74f66811103ffa7d2d566ff 100644 (file)
--- a/index.php
+++ b/index.php
@@ -96,7 +96,7 @@ if (isset($_GET["dump"])) {
                                        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";
                        }
                }
        }
index 53d06bd916c22ad10dc4e87fbce46e6ea56a4372..3e9d0e8786fb51d272f6ebfaa9f77d0f4afcf073 100644 (file)
@@ -1,15 +1,16 @@
 <?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"])
@@ -17,15 +18,40 @@ if ($_POST && !$error) {
                        . (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"])) { ?>
@@ -33,3 +59,11 @@ $collations = get_vals("SHOW CHARACTER SETS");
 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>