]> git.joonet.de Git - adminer.git/commitdiff
Driver specific routines
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 28 Apr 2010 00:11:39 +0000 (00:11 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 28 Apr 2010 00:11:39 +0000 (00:11 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1508 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/db.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/editing.inc.php

index 0e5c9dce94b5d84238a08b47f12aba4685973097..13c210bc575cd86e950f1b7d9beb79ade559047f 100644 (file)
@@ -94,12 +94,12 @@ if (support("view")) {
 }
 if (support("routine")) {
        echo "<h3>" . lang('Routines') . "</h3>\n";
-       $result = $connection->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . $connection->quote(DB));
-       if ($result->num_rows) {
-               odd('');
+       $routines = routines();
+       if ($routines) {
                echo "<table cellspacing='0'>\n";
                echo '<thead><tr><th>' . lang('Name') . '<td>' . lang('Type') . '<td>' . lang('Return type') . "<td>&nbsp;</thead>\n";
-               while ($row = $result->fetch_assoc()) {
+               odd('');
+               foreach ($routines as $row) {
                        echo '<tr' . odd() . '>';
                        echo '<th><a href="' . h(ME) . ($row["ROUTINE_TYPE"] == "FUNCTION" ? 'callf=' : 'call=') . urlencode($row["ROUTINE_NAME"]) . '">' . h($row["ROUTINE_NAME"]) . '</a>';
                        echo '<td>' . h($row["ROUTINE_TYPE"]);
index 96317faa274fd2ff3c6f90ed5a8234bfd31b4a8a..00b578647de0339557c44567375d697fc9f78351 100644 (file)
@@ -681,6 +681,53 @@ if (!defined("DRIVER")) {
                );
        }
        
+       /** Get information about stored routine
+       * @param string
+       * @param string FUNCTION or PROCEDURE
+       * @return array ("fields" => array("field" => , "type" => , "length" => , "unsigned" => , "inout" => , "collation" => ), "returns" => , "definition" => )
+       */
+       function routine($name, $type) {
+               global $connection, $enum_length, $inout, $types;
+               $aliases = array("bit" => "tinyint", "bool" => "tinyint", "boolean" => "tinyint", "integer" => "int", "double precision" => "float", "real" => "float", "dec" => "decimal", "numeric" => "decimal", "fixed" => "decimal", "national char" => "char", "national varchar" => "varchar");
+               $type_pattern = "((" . implode("|", array_keys($types + $aliases)) . ")(?:\\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 = $connection->result("SHOW CREATE $type " . idf_escape($name), 2);
+               preg_match("~\\(((?:$pattern\\s*,?)*)\\)" . ($type == "FUNCTION" ? "\\s*RETURNS\\s+$type_pattern" : "") . "\\s*(.*)~is", $create, $match);
+               $fields = array();
+               preg_match_all("~$pattern\\s*,?~is", $match[1], $matches, PREG_SET_ORDER);
+               foreach ($matches as $param) {
+                       $name = str_replace("``", "`", $param[2]) . $param[3];
+                       $data_type = strtolower($param[5]);
+                       $fields[] = array(
+                               "field" => $name,
+                               "type" => (isset($aliases[$data_type]) ? $aliases[$data_type] : $data_type),
+                               "length" => preg_replace_callback("~$enum_length~s", 'normalize_enum', $param[6]),
+                               "unsigned" => strtolower(preg_replace('~\\s+~', ' ', trim("$param[8] $param[7]"))),
+                               "full_type" => $param[4],
+                               "inout" => strtoupper($param[1]),
+                               "collation" => strtolower($param[9]),
+                       );
+               }
+               if ($type != "FUNCTION") {
+                       return array("fields" => $fields, "definition" => $match[11]);
+               }
+               return array(
+                       "fields" => $fields,
+                       "returns" => array("type" => $match[12], "length" => $match[13], "unsigned" => $match[15], "collation" => $match[16]),
+                       "definition" => $match[17],
+               );
+       }
+       
+       function routines() {
+               global $connection;
+               $return = array();
+               $result = $connection->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . $connection->quote(DB));
+               while ($row = $result->fetch_assoc()) {
+                       $return[] = $row;
+               }
+               return $return;
+       }
+       
        /** Begin transaction
        * @return bool
        */
index 6582120aa5ed471f53f2e35a1906cfc4085e270e..58b5f026338d43a86e5fde79f682c74095b75333 100644 (file)
@@ -474,6 +474,14 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                );
        }
        
+       function routine($name, $type) {
+               // not supported by SQLite
+       }
+       
+       function routines() {
+               // not supported by SQLite
+       }
+       
        function begin() {
                return queries("BEGIN");
        }
index c53b04c4fe40cc9ce3a9a3cce38a6201d5e265f8..6aa71835c95f342c50c10e2fc7c65b80958f8298 100644 (file)
@@ -280,43 +280,6 @@ 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))), '\\')) . "'";
 }
 
-/** Get information about stored routine
-* @param string
-* @param string FUNCTION or PROCEDURE
-* @return array ("fields" => array("field" => , "type" => , "length" => , "unsigned" => , "inout" => , "collation" => ), "returns" => , "definition" => )
-*/
-function routine($name, $type) {
-       global $connection, $enum_length, $inout, $types;
-       $aliases = array("bit" => "tinyint", "bool" => "tinyint", "boolean" => "tinyint", "integer" => "int", "double precision" => "float", "real" => "float", "dec" => "decimal", "numeric" => "decimal", "fixed" => "decimal", "national char" => "char", "national varchar" => "varchar");
-       $type_pattern = "((" . implode("|", array_keys($types + $aliases)) . ")(?:\\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 = $connection->result("SHOW CREATE $type " . idf_escape($name), 2);
-       preg_match("~\\(((?:$pattern\\s*,?)*)\\)" . ($type == "FUNCTION" ? "\\s*RETURNS\\s+$type_pattern" : "") . "\\s*(.*)~is", $create, $match);
-       $fields = array();
-       preg_match_all("~$pattern\\s*,?~is", $match[1], $matches, PREG_SET_ORDER);
-       foreach ($matches as $param) {
-               $name = str_replace("``", "`", $param[2]) . $param[3];
-               $data_type = strtolower($param[5]);
-               $fields[] = array(
-                       "field" => $name,
-                       "type" => (isset($aliases[$data_type]) ? $aliases[$data_type] : $data_type),
-                       "length" => preg_replace_callback("~$enum_length~s", 'normalize_enum', $param[6]),
-                       "unsigned" => strtolower(preg_replace('~\\s+~', ' ', trim("$param[8] $param[7]"))),
-                       "full_type" => $param[4],
-                       "inout" => strtoupper($param[1]),
-                       "collation" => strtolower($param[9]),
-               );
-       }
-       if ($type != "FUNCTION") {
-               return array("fields" => $fields, "definition" => $match[11]);
-       }
-       return array(
-               "fields" => $fields,
-               "returns" => array("type" => $match[12], "length" => $match[13], "unsigned" => $match[15], "collation" => $match[16]),
-               "definition" => $match[17],
-       );
-}
-
 /** Issue grant or revoke commands
 * @param string GRANT or REVOKE
 * @param array