From c33fc8e7660a296a193f3a88d43e41babe74bf93 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 31 May 2011 14:29:11 +0100 Subject: [PATCH] Moved code for generating the sql query that creates a routine into a function. --- libraries/db_routines.inc.php | 107 +++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 48 deletions(-) diff --git a/libraries/db_routines.inc.php b/libraries/db_routines.inc.php index deab7d5405..9fa4c6f4b2 100644 --- a/libraries/db_routines.inc.php +++ b/libraries/db_routines.inc.php @@ -545,50 +545,11 @@ function displayRoutineEditor($mode, $operation, $routine, $errors) { } // displayRoutineEditor() /** - * ### MAIN ########################################################################################################## + * Compose the query necessary to create a routine from an HTTP request. */ +function createQueryFromRequest() { + global $_REQUEST, $routine_errors, $param_sqldataaccess; -// $url_query .= '&goto=db_routines.php' . rawurlencode("?db=$db"); // FIXME - -/** - * Keep a list of errors that occured while processing an 'Add' or 'Edit' operation. - */ -$routine_errors = array(); - -/** - * Handle all user requests other than the default of listing routines - */ -if (! empty($_GET['exportroutine']) && ! empty($_GET['routinename']) && ! 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'])) { - $create_proc = ''; - if (! empty($_REQUEST['ajax_request'])) { - $extra_data = array('title' => sprintf(__('Export of routine %s'), $routine_name)); - PMA_ajaxResponse($create_proc, true, $extra_data); - } else { - echo '
' . "\n" - . ' ' . sprintf(__('Export of routine %s'), $routine_name) . '' . "\n" - . $create_proc . "\n" - . '
'; - } - } else { - $response = __('Error in Processing Request') . ' : ' - . sprintf(__('No routine with name %s found in database %s'), - $routine_name, htmlspecialchars(PMA_backquote($db))); - $response = PMA_message::error($response); - if (! empty($_REQUEST['ajax_request'])) { - PMA_ajaxResponse($response, false); - } else { - $response->display(); - } - } -} else if (! empty($_REQUEST['routine_process_addroutine']) || ! empty($_REQUEST['routine_process_editroutine'])) { - /** - * Handle a request to create/edit a routine - */ $query = 'CREATE '; if (! empty($_REQUEST['routine_definer']) && strpos($_REQUEST['routine_definer'], '@') !== false) { $arr = explode('@', $_REQUEST['routine_definer']); @@ -669,6 +630,55 @@ if (! empty($_GET['exportroutine']) && ! empty($_GET['routinename']) && ! empty( } else { $routine_errors[] = __('You must provide a routine Definition.'); } + return $query; +} // end createQueryFromRequest() + +/** + * ### MAIN ########################################################################################################## + */ + +// $url_query .= '&goto=db_routines.php' . rawurlencode("?db=$db"); // FIXME + +/** + * Keep a list of errors that occured while processing an 'Add' or 'Edit' operation. + */ +$routine_errors = array(); + +/** + * Handle all user requests other than the default of listing routines + */ +if (! empty($_GET['exportroutine']) && ! empty($_GET['routinename']) && ! 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'])) { + $create_proc = ''; + if (! empty($_REQUEST['ajax_request'])) { + $extra_data = array('title' => sprintf(__('Export of routine %s'), $routine_name)); + PMA_ajaxResponse($create_proc, true, $extra_data); + } else { + echo '
' . "\n" + . ' ' . sprintf(__('Export of routine %s'), $routine_name) . '' . "\n" + . $create_proc . "\n" + . '
'; + } + } else { + $response = __('Error in Processing Request') . ' : ' + . sprintf(__('No routine with name %s found in database %s'), + $routine_name, htmlspecialchars(PMA_backquote($db))); + $response = PMA_message::error($response); + if (! empty($_REQUEST['ajax_request'])) { + PMA_ajaxResponse($response, false); + } else { + $response->display(); + } + } +} else if (! empty($_REQUEST['routine_process_addroutine']) || ! empty($_REQUEST['routine_process_editroutine'])) { + /** + * Handle a request to create/edit a routine + */ + $routine_query = createQueryFromRequest(); if (! count($routine_errors)) { // Execute the created query if (! empty($_REQUEST['routine_process_editroutine'])) { @@ -685,9 +695,9 @@ if (! empty($_GET['exportroutine']) && ! empty($_GET['routinename']) && ! empty( $routine_errors[] = sprintf(__('Query "%s" failed'), $drop_routine) . '
' . __('MySQL said: ') . PMA_DBI_getError(null); } else { - $result = PMA_DBI_try_query($query); + $result = PMA_DBI_try_query($routine_query); if (! $result) { - $routine_errors[] = sprintf(__('Query "%s" failed'), $query) . '
' + $routine_errors[] = sprintf(__('Query "%s" failed'), $routine_query) . '
' . __('MySQL said: ') . PMA_DBI_getError(null); // We dropped the old routine, but were unable to create the new one // Try to restore the backup query @@ -707,21 +717,22 @@ if (! empty($_GET['exportroutine']) && ! empty($_GET['routinename']) && ! empty( echo '' . PMA_SQP_formatHtml(PMA_SQP_parse($drop_routine)) . '

' - . PMA_SQP_formatHtml(PMA_SQP_parse($query)) + . PMA_SQP_formatHtml(PMA_SQP_parse($routine_query)) . '
'; } } } else { - $result = PMA_DBI_try_query($query); + // 'Add a new routine' mode + $result = PMA_DBI_try_query($routine_query); if (! $result) { - $routine_errors[] = sprintf(__('Query "%s" failed'), $query) . '

' + $routine_errors[] = sprintf(__('Query "%s" failed'), $routine_query) . '

' . __('MySQL said: ') . PMA_DBI_getError(null); } else { $message = PMA_Message::success(__('Routine %1$s has been created.')); $message->addParam(PMA_backquote($_REQUEST['routine_name'])); $message->display(); echo '' - . PMA_SQP_formatHtml(PMA_SQP_parse($query)) + . PMA_SQP_formatHtml(PMA_SQP_parse($routine_query)) . ''; } }