mirror of
https://github.com/vrana/adminer.git
synced 2025-12-16 13:30:29 +01:00
MySQL: Use information_schema to get routine definition (fix #1179)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
## Adminer dev
|
## Adminer dev
|
||||||
- Autocomplete: fix in empty textarea (bug #1173)
|
- Autocomplete: fix in empty textarea (bug #1173)
|
||||||
|
- MySQL: Use information_schema to get routine definition (bug #1179)
|
||||||
- PostgreSQL: Mark unique partial indexes as unique (bug #1172)
|
- PostgreSQL: Mark unique partial indexes as unique (bug #1172)
|
||||||
- ClickHouse: Fix offset (bug #1188)
|
- ClickHouse: Fix offset (bug #1188)
|
||||||
- Plugins: Methods showVariables() and showStatus() (bug #1157)
|
- Plugins: Methods showVariables() and showStatus() (bug #1157)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ if (!$error && $_POST) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = (isset($_GET["callf"]) ? "SELECT " : "CALL ") . ($routine["returns"]["type"] == "record" ? "* FROM " : "") . table($PROCEDURE) . "(" . implode(", ", $call) . ")";
|
$query = (isset($_GET["callf"]) ? "SELECT " : "CALL ") . (idx($routine["returns"], "type") == "record" ? "* FROM " : "") . table($PROCEDURE) . "(" . implode(", ", $call) . ")";
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
$result = connection()->multi_query($query);
|
$result = connection()->multi_query($query);
|
||||||
$affected = connection()->affected_rows; // getting warnings overwrites this
|
$affected = connection()->affected_rows; // getting warnings overwrites this
|
||||||
|
|||||||
@@ -893,36 +893,27 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
* @return Routine
|
* @return Routine
|
||||||
*/
|
*/
|
||||||
function routine(string $name, string $type): array {
|
function routine(string $name, string $type): array {
|
||||||
$aliases = array("bool", "boolean", "integer", "double precision", "real", "dec", "numeric", "fixed", "national char", "national varchar");
|
$fields = get_rows("SELECT
|
||||||
$space = "(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)";
|
PARAMETER_NAME field,
|
||||||
$enum = driver()->enumLength;
|
DATA_TYPE type,
|
||||||
$type_pattern = "((" . implode("|", array_merge(array_keys(driver()->types()), $aliases)) . ")\\b(?:\\s*\\(((?:[^'\")]|$enum)++)\\))?"
|
CHARACTER_MAXIMUM_LENGTH length,
|
||||||
. "\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?)(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s,]+)['\"]?)?(?:\\s*COLLATE\\s*['\"]?[^'\"\\s,]+['\"]?)?"; //! store COLLATE
|
REGEXP_REPLACE(DTD_IDENTIFIER, '^[^ ]+ ', '') `unsigned`,
|
||||||
$pattern = "$space*(" . ($type == "FUNCTION" ? "" : driver()->inout) . ")?\\s*(?:`((?:[^`]|``)*)`\\s*|\\b(\\S+)\\s+)$type_pattern";
|
1 `null`,
|
||||||
$create = get_val("SHOW CREATE $type " . idf_escape($name), 2);
|
DTD_IDENTIFIER full_type,
|
||||||
preg_match("~\\(((?:$pattern\\s*,?)*)\\)\\s*" . ($type == "FUNCTION" ? "RETURNS\\s+$type_pattern\\s+" : "") . "(.*)~is", $create, $match);
|
PARAMETER_MODE `inout`,
|
||||||
$fields = array();
|
CHARACTER_SET_NAME collation
|
||||||
preg_match_all("~$pattern\\s*,?~is", $match[1], $matches, PREG_SET_ORDER);
|
FROM information_schema.PARAMETERS
|
||||||
foreach ($matches as $param) {
|
WHERE SPECIFIC_SCHEMA = DATABASE() AND ROUTINE_TYPE = '$type' AND SPECIFIC_NAME = " . q($name) . "
|
||||||
$fields[] = array(
|
ORDER BY ORDINAL_POSITION");
|
||||||
"field" => str_replace("``", "`", $param[2]) . $param[3],
|
$return = connection()->query("SELECT ROUTINE_COMMENT comment, ROUTINE_DEFINITION definition, 'SQL' language
|
||||||
"type" => strtolower($param[5]),
|
FROM information_schema.ROUTINES
|
||||||
"length" => preg_replace_callback("~$enum~s", 'Adminer\normalize_enum', $param[6]),
|
WHERE ROUTINE_SCHEMA = DATABASE() AND ROUTINE_TYPE = '$type' AND ROUTINE_NAME = " . q($name))->fetch_assoc();
|
||||||
"unsigned" => strtolower(preg_replace('~\s+~', ' ', trim("$param[8] $param[7]"))),
|
if ($fields && $fields[0]['field'] == '') {
|
||||||
"null" => true,
|
$return['returns'] = array_shift($fields);
|
||||||
"full_type" => $param[4],
|
|
||||||
"inout" => strtoupper($param[1]),
|
|
||||||
"collation" => strtolower($param[9]),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return array(
|
$return['fields'] = $fields;
|
||||||
"fields" => $fields,
|
/** @phpstan-var Routine */
|
||||||
"comment" => get_val("SELECT ROUTINE_COMMENT FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = DATABASE() AND ROUTINE_NAME = " . q($name)),
|
return $return;
|
||||||
) + ($type != "FUNCTION" ? array("definition" => $match[11]) : array(
|
|
||||||
"returns" => array("type" => $match[12], "length" => $match[13], "unsigned" => $match[15], "collation" => $match[16]),
|
|
||||||
"definition" => $match[17],
|
|
||||||
"language" => "SQL", // available in information_schema.ROUTINES.BODY_STYLE
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get list of routines
|
/** Get list of routines
|
||||||
|
|||||||
Reference in New Issue
Block a user