diff --git a/libraries/db_routines.inc.php b/libraries/db_routines.inc.php
index a80afc4235..19c88b12b5 100644
--- a/libraries/db_routines.inc.php
+++ b/libraries/db_routines.inc.php
@@ -374,6 +374,10 @@ function getFormInputFromRoutineName($db, $name, $all = true)
$query = "SELECT $fields FROM INFORMATION_SCHEMA.ROUTINES WHERE $where;";
$routine = PMA_DBI_fetch_single_row($query);
+ if (! $routine) {
+ return false;
+ }
+
// Get required data
$retval['name'] = $routine['SPECIFIC_NAME'];
$retval['type'] = $routine['ROUTINE_TYPE'];
@@ -1021,18 +1025,20 @@ function routineMakeRowForList($routine, $ct = 0) {
// we will show a dialog to get values for these parameters,
// otherwise we can execute it directly.
$routine_details = getFormInputFromRoutineName($db, $routine['SPECIFIC_NAME'], false);
- $execute_action = 'execute_routine';
- for ($i=0; $i<$routine_details['num_params']; $i++) {
- if ($routine_details['type'] == 'PROCEDURE' && $routine_details['param_dir'][$i] == 'OUT') {
- continue;
+ if ($routine !== false) {
+ $execute_action = 'execute_routine';
+ for ($i=0; $i<$routine_details['num_params']; $i++) {
+ if ($routine_details['type'] == 'PROCEDURE' && $routine_details['param_dir'][$i] == 'OUT') {
+ continue;
+ }
+ $execute_action = 'execute_dialog';
+ break;
}
- $execute_action = 'execute_dialog';
- break;
+ $execlink = '' . $titles['Execute'] . '';
}
- $execlink = '' . $titles['Execute'] . '';
}
if ($routine['ROUTINE_DEFINITION'] !== NULL) {
$exprlink = ' $query) {
+ $resource = PMA_DBI_query($query);
+ while (true) {
+ if(! PMA_DBI_more_results()) {
+ break;
+ }
+ PMA_DBI_next_result();
+ }
+ if (substr($query, 0, 6) == 'SELECT') {
+ $result = $resource;
+ } else if (substr($query, 0, 4) == 'CALL') {
+ $affected = PMA_DBI_affected_rows() - PMA_DBI_num_rows($resource);
}
}
- }
- if ($routine['type'] == 'PROCEDURE') {
- $queries[] = "CALL " . PMA_backquote($routine['name'])
- . "(" . implode(', ', $args) . ");\n";
- if (count($end_query)) {
- $queries[] = "SELECT " . implode(', ', $end_query) . ";\n";
+
+ // If any of the queries failed, we wouldn't have gotten
+ // this far, so we simply show a success message.
+ $message = __('Your SQL query has been executed successfully');
+ if ($routine['type'] == 'PROCEDURE') {
+ $message .= '
';
+ $message .= sprintf(__('%s row(s) affected by the last statement inside the procedure'), $affected);
}
- } else {
- $queries[] = "SELECT " . PMA_backquote($routine['name'])
- . "(" . implode(', ', $args) . ") "
- . "AS " . PMA_backquote($routine['name']) . ";\n";
- }
- // Execute the queries
- $affected = 0;
- $result = null;
- foreach ($queries as $num => $query) {
- $resource = PMA_DBI_query($query);
- while (true) {
- if(! PMA_DBI_more_results()) {
- break;
+ $message = PMA_message::success($message);
+
+ // Pass the sql query through the "pretty printer"
+ // and display it.
+ $output = '';
+ $output .= PMA_SQP_formatHtml(PMA_SQP_parse(implode($queries)));
+ $output .= '';
+
+ // Display results
+ if ($result) {
+ $output .= "