From a31c41a6699e6f3fe0afa301be89a3d1792b4f4e Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Wed, 1 Jun 2011 14:11:12 +0100 Subject: [PATCH] Cleaned up the code for displaying the list of routines. --- libraries/db_routines.inc.php | 177 ++++++++++++++++------------------ 1 file changed, 84 insertions(+), 93 deletions(-) diff --git a/libraries/db_routines.inc.php b/libraries/db_routines.inc.php index 7efdfce9a0..e885046e16 100644 --- a/libraries/db_routines.inc.php +++ b/libraries/db_routines.inc.php @@ -633,12 +633,12 @@ $routine_errors = array(); /** * Handle all user requests other than the default of listing routines */ -if (! empty($_GET['exportroutine']) && ! empty($_GET['routinename']) && ! empty($_GET['routinetype'])) { +if (! empty($_GET['exportroutine']) && ! empty($_GET['routine_name']) && ! empty($_GET['routinetype'])) { /** * Display the export for a routine. */ - $routine_name = htmlspecialchars(PMA_backquote($_GET['routinename'])); - if ($create_proc = PMA_DBI_get_definition($db, $_GET['routinetype'], $_GET['routinename'])) { + $routine_name = htmlspecialchars(PMA_backquote($_GET['routine_name'])); + if ($create_proc = PMA_DBI_get_definition($db, $_GET['routinetype'], $_GET['routine_name'])) { $create_proc = ''; if (! empty($_REQUEST['ajax_request'])) { $extra_data = array('title' => sprintf(__('Export of routine %s'), $routine_name)); @@ -771,114 +771,104 @@ if (count($routine_errors) || ( empty($_REQUEST['routine_process_addroutine']) & */ $conditional_class_add = ''; $conditional_class_edit = ''; +$conditional_class_exec = ''; $conditional_class_drop = ''; $conditional_class_export = ''; if ($GLOBALS['cfg']['AjaxEnable']) { $conditional_class_add = 'class="add_routine_anchor"'; $conditional_class_edit = 'class="edit_routine_anchor"'; + $conditional_class_exec = 'class="exec_routine_anchor"'; $conditional_class_drop = 'class="drop_routine_anchor"'; $conditional_class_export = 'class="export_routine_anchor"'; } +/** + * Get the routines. + */ +$columns = "`SPECIFIC_NAME`, `ROUTINE_NAME`, `ROUTINE_TYPE`, `DTD_IDENTIFIER`, `ROUTINE_DEFINITION`"; +$where = "ROUTINE_SCHEMA='" . PMA_sqlAddslashes($db,true) . "'"; +$routines = PMA_DBI_fetch_result("SELECT $columns FROM `INFORMATION_SCHEMA`.`ROUTINES` WHERE $where;"); + /** * Display a list of available routines */ - -$routines = PMA_DBI_fetch_result('SELECT SPECIFIC_NAME,ROUTINE_NAME,ROUTINE_TYPE,DTD_IDENTIFIER,ROUTINE_DEFINITION FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA= \'' . PMA_sqlAddslashes($db,true) . '\';'); - -echo '
' . "\n"; -echo ' ' . __('Routines') . '' . "\n"; - +echo "\n\n"; +echo "\n"; +echo "
\n"; +echo " " . __('Routines') . "\n"; if (! $routines) { - echo __('There are no routines to display.'); + echo " " . __('There are no routines to display.') . "\n"; } else { - echo ''; - echo ''; - echo sprintf(' - - - - - - - - ', - __('Name'), - __('Type'), - __('Return type')); + echo "
\n"; + echo " " . __('There are no routines to display.') . "\n"; + echo "
\n"; + echo "
%s    %s%s
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; $ct=0; - $delimiter = '//'; + // Display each routine foreach ($routines as $routine) { - - // information_schema (at least in MySQL 5.0.45) - // does not return the routine parameters - // so we rely on PMA_DBI_get_definition() which - // uses SHOW CREATE - - $create_proc = PMA_DBI_get_definition($db, $routine['ROUTINE_TYPE'], $routine['SPECIFIC_NAME']); - $definition = 'DROP ' . $routine['ROUTINE_TYPE'] . ' ' . PMA_backquote($routine['SPECIFIC_NAME']) . $delimiter . "\n" - . $create_proc . "\n"; - - //if ($routine['ROUTINE_TYPE'] == 'PROCEDURE') { - // $sqlUseProc = 'CALL ' . $routine['SPECIFIC_NAME'] . '()'; - //} else { - // $sqlUseProc = 'SELECT ' . $routine['SPECIFIC_NAME'] . '()'; - /* this won't get us far: to really use the function - i'd need to know how many parameters the function needs and then create - something to ask for them. As i don't see this directly in - the table i am afraid that requires parsing the ROUTINE_DEFINITION - and i don't really need that now so i simply don't offer - a method for running the function*/ - //} - if ($routine['ROUTINE_TYPE'] == 'PROCEDURE') { - $sqlDropProc = 'DROP PROCEDURE IF EXISTS ' . PMA_backquote($routine['SPECIFIC_NAME']); - } else { - $sqlDropProc = 'DROP FUNCTION IF EXISTS ' . PMA_backquote($routine['SPECIFIC_NAME']); + // Do the logic first + $rowclass = ($ct % 2 == 0) ? 'even' : 'odd'; + $editlink = $titles['NoEdit']; + $execlink = $titles['NoExecute']; + $exprlink = $titles['NoExport']; + $droplink = $titles['NoDrop']; + $sql_drop = sprintf('DROP %s IF EXISTS %s', + $routine['ROUTINE_TYPE'], + PMA_backquote($routine['SPECIFIC_NAME'])); + if ($routine['ROUTINE_DEFINITION'] !== NULL + && PMA_currentUserHasPrivilege('ALTER ROUTINE', $db) + && PMA_currentUserHasPrivilege('CREATE ROUTINE', $db)) { + $editlink = '' . $titles['Edit'] . ''; } - - // FIXME: this whole sprintf business is a mess and is hardly readable! - echo sprintf(' - - - - - - - - ', - ($ct % 2 == 0) ? 'even' : 'odd', - $sqlDropProc, - $routine['ROUTINE_NAME'], - ($routine['ROUTINE_DEFINITION'] !== NULL - && PMA_currentUserHasPrivilege('ALTER ROUTINE', $db) - && PMA_currentUserHasPrivilege('CREATE ROUTINE', $db)) - ? '' . $titles['Edit'] . '' - : $titles['NoEdit'], - (PMA_currentUserHasPrivilege('EXECUTE', $db)) - ? PMA_linkOrButton('#', $titles['Execute']) - : $titles['NoExecute'], - ($routine['ROUTINE_DEFINITION'] !== NULL) - ? '' . $titles['Export'] . '' - : $titles['NoExport'], - (PMA_currentUserHasPrivilege('ALTER ROUTINE', $db)) - ? '' . $titles['Drop'] . '' - : $titles['NoDrop'], - $routine['ROUTINE_TYPE'], - $routine['DTD_IDENTIFIER']); + if (PMA_currentUserHasPrivilege('EXECUTE', $db)) { + $execlink = '' + . $titles['Execute'] . ''; + } + if ($routine['ROUTINE_DEFINITION'] !== NULL) { + $exprlink = '' . $titles['Export'] . ''; + } + if (PMA_currentUserHasPrivilege('ALTER ROUTINE', $db)) { + $droplink = '' . $titles['Drop'] . ''; + } + // Display a row of data + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; $ct++; } - echo '
" . __('Name') . "    " . __('Type') . "" . __('Return type') . "
%s%s%s%s%s%s%s%s
\n"; + echo " $sql_drop\n"; + echo " {$routine['ROUTINE_NAME']}\n"; + echo " $editlink$execlink$exprlink$droplink{$routine['ROUTINE_TYPE']}{$routine['DTD_IDENTIFIER']}
'; + echo " \n"; } -echo '
' . "\n"; +echo "
\n"; +echo "\n\n"; /** * Display the form for adding a new routine, if the user has the privileges. @@ -886,7 +876,8 @@ echo '' . "\n"; echo '' . "\n"; echo '
' . "\n"; if (PMA_currentUserHasPrivilege('CREATE ROUTINE', $db)) { - echo '' . "\n" + echo '' . "\n" . PMA_getIcon('b_routine_add.png') . "\n" . __('Add a new Routine') . '' . "\n"; } else { @@ -895,5 +886,5 @@ if (PMA_currentUserHasPrivilege('CREATE ROUTINE', $db)) { } echo PMA_showMySQLDocu('SQL-Syntax', 'CREATE_PROCEDURE') . "\n"; echo '
' . "\n"; -echo '' . "\n"; +echo '' . "\n\n"; ?>