diff options
Diffstat (limited to 'libraries/classes/Database')
-rw-r--r-- | libraries/classes/Database/Routines.php | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/libraries/classes/Database/Routines.php b/libraries/classes/Database/Routines.php index 31a116d7c0..729bcc1492 100644 --- a/libraries/classes/Database/Routines.php +++ b/libraries/classes/Database/Routines.php @@ -8,6 +8,7 @@ use PhpMyAdmin\Charsets; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Message; +use PhpMyAdmin\Query\Generator as QueryGenerator; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Statements\CreateStatement; @@ -18,7 +19,9 @@ use PhpMyAdmin\Util; use function __; use function _ngettext; +use function array_column; use function array_merge; +use function array_multisort; use function count; use function explode; use function htmlentities; @@ -38,6 +41,7 @@ use function substr; use function trim; use const ENT_QUOTES; +use const SORT_ASC; /** * Functions for routine management. @@ -289,7 +293,7 @@ class Routines exit; } - $routines = $this->dbi->getRoutines($db, $_POST['item_type'], $_POST['item_name']); + $routines = self::getDetails($this->dbi, $db, $_POST['item_type'], $_POST['item_name']); $routine = $routines[0]; $this->response->addJSON( 'name', @@ -1597,4 +1601,71 @@ class Routines $this->response->addHTML($message->getDisplay()); } + + /** + * returns details about the PROCEDUREs or FUNCTIONs for a specific database + * or details about a specific routine + * + * @param string $db db name + * @param string|null $which PROCEDURE | FUNCTION or null for both + * @param string $name name of the routine (to fetch a specific routine) + * + * @return array information about PROCEDUREs or FUNCTIONs + */ + public static function getDetails( + DatabaseInterface $dbi, + string $db, + ?string $which = null, + string $name = '' + ): array { + if (! $GLOBALS['cfg']['Server']['DisableIS']) { + $query = QueryGenerator::getInformationSchemaRoutinesRequest( + $dbi->escapeString($db), + isset($which) && in_array($which, ['FUNCTION', 'PROCEDURE']) ? $which : null, + empty($name) ? null : $dbi->escapeString($name) + ); + $routines = $dbi->fetchResult($query); + } else { + $routines = []; + + if ($which === 'FUNCTION' || $which == null) { + $query = 'SHOW FUNCTION STATUS' + . " WHERE `Db` = '" . $dbi->escapeString($db) . "'"; + if ($name) { + $query .= " AND `Name` = '" + . $dbi->escapeString($name) . "'"; + } + + $routines = $dbi->fetchResult($query); + } + + if ($which === 'PROCEDURE' || $which == null) { + $query = 'SHOW PROCEDURE STATUS' + . " WHERE `Db` = '" . $dbi->escapeString($db) . "'"; + if ($name) { + $query .= " AND `Name` = '" + . $dbi->escapeString($name) . "'"; + } + + $routines = array_merge($routines, $dbi->fetchResult($query)); + } + } + + $ret = []; + foreach ($routines as $routine) { + $ret[] = [ + 'db' => $routine['Db'], + 'name' => $routine['Name'], + 'type' => $routine['Type'], + 'definer' => $routine['Definer'], + 'returns' => $routine['DTD_IDENTIFIER'] ?? '', + ]; + } + + // Sort results by name + $name = array_column($ret, 'name'); + array_multisort($name, SORT_ASC, $ret); + + return $ret; + } } |