1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-12 01:24:17 +02:00

Driver specific routines

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1508 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana
2010-04-28 00:11:39 +00:00
parent 5edca0679c
commit 02a172e1ac
4 changed files with 59 additions and 41 deletions

View 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
*/

View 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");
}