@@ -204,9 +204,9 @@ public function handleRequestCreateOrEdit(array $errors, $db)
204204 } else {
205205 // Backup the old routine, in case something goes wrong
206206 if ($ _POST ['item_original_type ' ] === 'FUNCTION ' ) {
207- $ create_routine = $ this ->dbi -> getDefinition ( $ db , ' FUNCTION ' , $ _POST ['item_original_name ' ]);
207+ $ create_routine = self :: getFunctionDefinition ( $ this ->dbi , $ db , $ _POST ['item_original_name ' ]);
208208 } else {
209- $ create_routine = $ this ->dbi -> getDefinition ( $ db , ' PROCEDURE ' , $ _POST ['item_original_name ' ]);
209+ $ create_routine = self :: getProcedureDefinition ( $ this ->dbi , $ db , $ _POST ['item_original_name ' ]);
210210 }
211211
212212 $ privilegesBackup = $ this ->backupPrivileges ();
@@ -575,7 +575,11 @@ public function getDataFromName($name, $type, $all = true): ?array
575575 $ retval ['item_name ' ] = $ routine ['SPECIFIC_NAME ' ];
576576 $ retval ['item_type ' ] = $ routine ['ROUTINE_TYPE ' ];
577577
578- $ definition = $ this ->dbi ->getDefinition ($ GLOBALS ['db ' ], $ routine ['ROUTINE_TYPE ' ], $ routine ['SPECIFIC_NAME ' ]);
578+ if ($ routine ['ROUTINE_TYPE ' ] === 'FUNCTION ' ) {
579+ $ definition = self ::getFunctionDefinition ($ this ->dbi , $ GLOBALS ['db ' ], $ routine ['SPECIFIC_NAME ' ]);
580+ } else {
581+ $ definition = self ::getProcedureDefinition ($ this ->dbi , $ GLOBALS ['db ' ], $ routine ['SPECIFIC_NAME ' ]);
582+ }
579583
580584 if ($ definition === null ) {
581585 return null ;
@@ -1474,7 +1478,12 @@ public function getRow(array $routine, $rowClass = '')
14741478 // we will show a dialog to get values for these parameters,
14751479 // otherwise we can execute it directly.
14761480
1477- $ definition = $ this ->dbi ->getDefinition ($ GLOBALS ['db ' ], $ routine ['type ' ], $ routine ['name ' ]);
1481+ if ($ routine ['type ' ] === 'FUNCTION ' ) {
1482+ $ definition = self ::getFunctionDefinition ($ this ->dbi , $ GLOBALS ['db ' ], $ routine ['name ' ]);
1483+ } else {
1484+ $ definition = self ::getProcedureDefinition ($ this ->dbi , $ GLOBALS ['db ' ], $ routine ['name ' ]);
1485+ }
1486+
14781487 $ executeAction = '' ;
14791488
14801489 if ($ definition !== null ) {
@@ -1540,11 +1549,14 @@ public function export(): void
15401549 return ;
15411550 }
15421551
1543- if ($ _GET ['item_type ' ] !== 'FUNCTION ' && $ _GET ['item_type ' ] !== 'PROCEDURE ' ) {
1552+ if ($ _GET ['item_type ' ] === 'FUNCTION ' ) {
1553+ $ routineDefinition = self ::getFunctionDefinition ($ this ->dbi , $ GLOBALS ['db ' ], $ _GET ['item_name ' ]);
1554+ } elseif ($ _GET ['item_type ' ] === 'PROCEDURE ' ) {
1555+ $ routineDefinition = self ::getProcedureDefinition ($ this ->dbi , $ GLOBALS ['db ' ], $ _GET ['item_name ' ]);
1556+ } else {
15441557 return ;
15451558 }
15461559
1547- $ routineDefinition = $ this ->dbi ->getDefinition ($ GLOBALS ['db ' ], $ _GET ['item_type ' ], $ _GET ['item_name ' ]);
15481560 $ exportData = false ;
15491561
15501562 if ($ routineDefinition !== null ) {
@@ -1660,4 +1672,24 @@ public static function getDetails(
16601672
16611673 return $ ret ;
16621674 }
1675+
1676+ public static function getFunctionDefinition (DatabaseInterface $ dbi , string $ db , string $ name ): ?string
1677+ {
1678+ $ result = $ dbi ->fetchValue (
1679+ 'SHOW CREATE FUNCTION ' . Util::backquote ($ db ) . '. ' . Util::backquote ($ name ),
1680+ 'Create Function '
1681+ );
1682+
1683+ return is_string ($ result ) ? $ result : null ;
1684+ }
1685+
1686+ public static function getProcedureDefinition (DatabaseInterface $ dbi , string $ db , string $ name ): ?string
1687+ {
1688+ $ result = $ dbi ->fetchValue (
1689+ 'SHOW CREATE PROCEDURE ' . Util::backquote ($ db ) . '. ' . Util::backquote ($ name ),
1690+ 'Create Procedure '
1691+ );
1692+
1693+ return is_string ($ result ) ? $ result : null ;
1694+ }
16631695}
0 commit comments