diff --git a/libraries/db_routines.inc.php b/libraries/db_routines.inc.php index 6967b3f4c5..371d0d6ed7 100644 --- a/libraries/db_routines.inc.php +++ b/libraries/db_routines.inc.php @@ -19,9 +19,10 @@ if (! defined('PHPMYADMIN')) { } // Some definitions -$param_datatypes = getSupportedDatatypes(); -$param_directions = array('IN', 'OUT', 'INOUT'); -$param_sqldataaccess = array('', 'CONTAINS SQL', 'NO SQL', 'READS SQL DATA', 'MODIFIES SQL DATA'); +$routine_process_error = false; +$param_datatypes = getSupportedDatatypes(); +$param_directions = array('IN', 'OUT', 'INOUT'); +$param_sqldataaccess = array('', 'CONTAINS SQL', 'NO SQL', 'READS SQL DATA', 'MODIFIES SQL DATA'); /** * This function processes the datatypes supported by the DB, as specified in $cfg['ColumnTypes'] @@ -191,23 +192,6 @@ function getFormInputFromRequest() // $url_query .= '&goto=db_routines.php' . rawurlencode("?db=$db"); // FIXME -/** - * Get all available routines - */ -$routines = PMA_DBI_fetch_result('SELECT SPECIFIC_NAME,ROUTINE_NAME,ROUTINE_TYPE,DTD_IDENTIFIER FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA= \'' . PMA_sqlAddslashes($db,true) . '\';'); - -/** - * Generate the conditional classes that will be used to attach jQuery events to links. - */ -$conditional_class_add = ''; -$conditional_class_drop = ''; -$conditional_class_export = ''; -if ($GLOBALS['cfg']['AjaxEnable']) { - $conditional_class_add = 'class="add_routine_anchor"'; - $conditional_class_drop = 'class="drop_procedure_anchor"'; - $conditional_class_export = 'class="export_procedure_anchor"'; -} - /** * Handle all user requests other than the default of listing routines */ @@ -225,57 +209,86 @@ if (! empty($_GET['exportroutine']) && ! empty($_GET['routinename']) && ! empty( /** * Handle a request to create a routine */ -// var_dump($_REQUEST); - $definer = ''; - if (! empty($_REQUEST['routine_definer'])) { - $definer = 'DEFINER ' . PMA_sqlAddSlashes($_REQUEST['routine_definer']); + + $query = 'CREATE '; + if (! empty($_REQUEST['routine_definer']) && strpos($_REQUEST['routine_definer'], '@') !== false) { + $arr = explode('@', $_REQUEST['routine_definer']); + $query .= 'DEFINER=' . PMA_backquote($arr[0]) . '@' . PMA_backquote($arr[1]) . ' '; + } + if ($_REQUEST['routine_type'] == 'FUNCTION' || $_REQUEST['routine_type'] == 'PROCEDURE') { + $query .= $_REQUEST['routine_type'] . ' '; + } else { + $routine_process_error = true; + } + if (! empty($_REQUEST['routine_name'])) { + $query .= PMA_backquote($_REQUEST['routine_name']) . ' '; + } else { + $routine_process_error = true; } - $name = PMA_sqlAddSlashes($_REQUEST['routine_name']); $params = ''; - if (! empty($_REQUEST['routine_param_dir']) && ! empty($_REQUEST['routine_param_name']) && ! empty($_REQUEST['routine_param_type']) - && is_array($_REQUEST['routine_param_dir']) && is_array($_REQUEST['routine_param_name']) && is_array($_REQUEST['routine_param_type'])) { - // FIXME: this is just wrong right now... + if (! empty($_REQUEST['routine_param_dir']) && ! empty($_REQUEST['routine_param_name']) + && ! empty($_REQUEST['routine_param_type']) && ! empty($_REQUEST['routine_param_length']) + && is_array($_REQUEST['routine_param_dir']) && is_array($_REQUEST['routine_param_name']) + && is_array($_REQUEST['routine_param_type']) && is_array($_REQUEST['routine_param_length'])) { + for ($i=0; $iaddParam(PMA_backquote($_REQUEST['routine_name'])); + $message->display(); + } +} + +if (! empty($_REQUEST['addroutine']) || ! empty($_REQUEST['routine_addparameter']) + || ! empty($_REQUEST['routine_removeparameter']) || ! empty($_REQUEST['routine_changetype']) + || $routine_process_error) { /** * Display a form used to create a new routine */ @@ -287,6 +300,14 @@ if (! empty($_GET['exportroutine']) && ! empty($_GET['routinename']) && ! empty( if ($GLOBALS['is_ajax_request'] != true) { echo "

" . __("Create Routine") . "

\n"; } + + // Some error + //TODO: better error handling: this is just ridiculous... + if ($routine_process_error) { + $msg = PMA_Message::error(__('Error: Some missing values')); + $msg->display(); + } + echo '
' . "\n" . PMA_generate_common_hidden_inputs($db, $table) . "
\n" @@ -391,9 +412,24 @@ if (! empty($_GET['exportroutine']) && ! empty($_GET['routinename']) && ! empty( exit; } +/** + * Generate the conditional classes that will be used to attach jQuery events to links. + */ +$conditional_class_add = ''; +$conditional_class_drop = ''; +$conditional_class_export = ''; +if ($GLOBALS['cfg']['AjaxEnable']) { + $conditional_class_add = 'class="add_routine_anchor"'; + $conditional_class_drop = 'class="drop_procedure_anchor"'; + $conditional_class_export = 'class="export_procedure_anchor"'; +} + /** * Display a list of available routines */ + +$routines = PMA_DBI_fetch_result('SELECT SPECIFIC_NAME,ROUTINE_NAME,ROUTINE_TYPE,DTD_IDENTIFIER FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA= \'' . PMA_sqlAddslashes($db,true) . '\';'); + echo '
' . "\n"; echo ' ' . __('Routines') . '' . "\n";