|
8 | 8 | use PhpMyAdmin\DatabaseInterface; |
9 | 9 | use PhpMyAdmin\Html\Generator; |
10 | 10 | use PhpMyAdmin\Message; |
| 11 | +use PhpMyAdmin\Query\Generator as QueryGenerator; |
11 | 12 | use PhpMyAdmin\ResponseRenderer; |
12 | 13 | use PhpMyAdmin\SqlParser\Parser; |
13 | 14 | use PhpMyAdmin\SqlParser\Statements\CreateStatement; |
|
18 | 19 |
|
19 | 20 | use function __; |
20 | 21 | use function _ngettext; |
| 22 | +use function array_column; |
21 | 23 | use function array_merge; |
| 24 | +use function array_multisort; |
22 | 25 | use function count; |
23 | 26 | use function explode; |
24 | 27 | use function htmlentities; |
|
38 | 41 | use function trim; |
39 | 42 |
|
40 | 43 | use const ENT_QUOTES; |
| 44 | +use const SORT_ASC; |
41 | 45 |
|
42 | 46 | /** |
43 | 47 | * Functions for routine management. |
@@ -289,7 +293,7 @@ public function handleRequestCreateOrEdit(array $errors, $db) |
289 | 293 | exit; |
290 | 294 | } |
291 | 295 |
|
292 | | - $routines = $this->dbi->getRoutines($db, $_POST['item_type'], $_POST['item_name']); |
| 296 | + $routines = self::getDetails($this->dbi, $db, $_POST['item_type'], $_POST['item_name']); |
293 | 297 | $routine = $routines[0]; |
294 | 298 | $this->response->addJSON( |
295 | 299 | 'name', |
@@ -1597,4 +1601,71 @@ public function export(): void |
1597 | 1601 |
|
1598 | 1602 | $this->response->addHTML($message->getDisplay()); |
1599 | 1603 | } |
| 1604 | + |
| 1605 | + /** |
| 1606 | + * returns details about the PROCEDUREs or FUNCTIONs for a specific database |
| 1607 | + * or details about a specific routine |
| 1608 | + * |
| 1609 | + * @param string $db db name |
| 1610 | + * @param string|null $which PROCEDURE | FUNCTION or null for both |
| 1611 | + * @param string $name name of the routine (to fetch a specific routine) |
| 1612 | + * |
| 1613 | + * @return array information about PROCEDUREs or FUNCTIONs |
| 1614 | + */ |
| 1615 | + public static function getDetails( |
| 1616 | + DatabaseInterface $dbi, |
| 1617 | + string $db, |
| 1618 | + ?string $which = null, |
| 1619 | + string $name = '' |
| 1620 | + ): array { |
| 1621 | + if (! $GLOBALS['cfg']['Server']['DisableIS']) { |
| 1622 | + $query = QueryGenerator::getInformationSchemaRoutinesRequest( |
| 1623 | + $dbi->escapeString($db), |
| 1624 | + isset($which) && in_array($which, ['FUNCTION', 'PROCEDURE']) ? $which : null, |
| 1625 | + empty($name) ? null : $dbi->escapeString($name) |
| 1626 | + ); |
| 1627 | + $routines = $dbi->fetchResult($query); |
| 1628 | + } else { |
| 1629 | + $routines = []; |
| 1630 | + |
| 1631 | + if ($which === 'FUNCTION' || $which == null) { |
| 1632 | + $query = 'SHOW FUNCTION STATUS' |
| 1633 | + . " WHERE `Db` = '" . $dbi->escapeString($db) . "'"; |
| 1634 | + if ($name) { |
| 1635 | + $query .= " AND `Name` = '" |
| 1636 | + . $dbi->escapeString($name) . "'"; |
| 1637 | + } |
| 1638 | + |
| 1639 | + $routines = $dbi->fetchResult($query); |
| 1640 | + } |
| 1641 | + |
| 1642 | + if ($which === 'PROCEDURE' || $which == null) { |
| 1643 | + $query = 'SHOW PROCEDURE STATUS' |
| 1644 | + . " WHERE `Db` = '" . $dbi->escapeString($db) . "'"; |
| 1645 | + if ($name) { |
| 1646 | + $query .= " AND `Name` = '" |
| 1647 | + . $dbi->escapeString($name) . "'"; |
| 1648 | + } |
| 1649 | + |
| 1650 | + $routines = array_merge($routines, $dbi->fetchResult($query)); |
| 1651 | + } |
| 1652 | + } |
| 1653 | + |
| 1654 | + $ret = []; |
| 1655 | + foreach ($routines as $routine) { |
| 1656 | + $ret[] = [ |
| 1657 | + 'db' => $routine['Db'], |
| 1658 | + 'name' => $routine['Name'], |
| 1659 | + 'type' => $routine['Type'], |
| 1660 | + 'definer' => $routine['Definer'], |
| 1661 | + 'returns' => $routine['DTD_IDENTIFIER'] ?? '', |
| 1662 | + ]; |
| 1663 | + } |
| 1664 | + |
| 1665 | + // Sort results by name |
| 1666 | + $name = array_column($ret, 'name'); |
| 1667 | + array_multisort($name, SORT_ASC, $ret); |
| 1668 | + |
| 1669 | + return $ret; |
| 1670 | + } |
1600 | 1671 | } |
0 commit comments