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:
parent
5edca0679c
commit
02a172e1ac
|
@ -94,12 +94,12 @@ if (support("view")) {
|
||||||
}
|
}
|
||||||
if (support("routine")) {
|
if (support("routine")) {
|
||||||
echo "<h3>" . lang('Routines') . "</h3>\n";
|
echo "<h3>" . lang('Routines') . "</h3>\n";
|
||||||
$result = $connection->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . $connection->quote(DB));
|
$routines = routines();
|
||||||
if ($result->num_rows) {
|
if ($routines) {
|
||||||
odd('');
|
|
||||||
echo "<table cellspacing='0'>\n";
|
echo "<table cellspacing='0'>\n";
|
||||||
echo '<thead><tr><th>' . lang('Name') . '<td>' . lang('Type') . '<td>' . lang('Return type') . "<td> </thead>\n";
|
echo '<thead><tr><th>' . lang('Name') . '<td>' . lang('Type') . '<td>' . lang('Return type') . "<td> </thead>\n";
|
||||||
while ($row = $result->fetch_assoc()) {
|
odd('');
|
||||||
|
foreach ($routines as $row) {
|
||||||
echo '<tr' . odd() . '>';
|
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 '<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"]);
|
echo '<td>' . h($row["ROUTINE_TYPE"]);
|
||||||
|
|
|
@ -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
|
/** Begin transaction
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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() {
|
function begin() {
|
||||||
return queries("BEGIN");
|
return queries("BEGIN");
|
||||||
}
|
}
|
||||||
|
|
|
@ -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))), '\\')) . "'";
|
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
|
/** Issue grant or revoke commands
|
||||||
* @param string GRANT or REVOKE
|
* @param string GRANT or REVOKE
|
||||||
* @param array
|
* @param array
|
||||||
|
|
Loading…
Reference in a new issue