/** * Composes the query necessary to create a routine from an HTTP request. * * @return string The CREATE [ROUTINE | PROCEDURE] query. */ function PMA_RTN_getQueryFromRequest() { global $_REQUEST, $errors, $param_sqldataaccess, $param_directions; $_REQUEST['item_type'] = isset($_REQUEST['item_type']) ? $_REQUEST['item_type'] : ''; $query = 'CREATE '; if (!empty($_REQUEST['item_definer'])) { if (strpos($_REQUEST['item_definer'], '@') !== false) { $arr = explode('@', $_REQUEST['item_definer']); $query .= 'DEFINER=' . PMA_Util::backquote($arr[0]); $query .= '@' . PMA_Util::backquote($arr[1]) . ' '; } else { $errors[] = __('The definer must be in the "username@hostname" format'); } } if ($_REQUEST['item_type'] == 'FUNCTION' || $_REQUEST['item_type'] == 'PROCEDURE') { $query .= $_REQUEST['item_type'] . ' '; } else { $errors[] = sprintf(__('Invalid routine type: "%s"'), htmlspecialchars($_REQUEST['item_type'])); } if (!empty($_REQUEST['item_name'])) { $query .= PMA_Util::backquote($_REQUEST['item_name']); } else { $errors[] = __('You must provide a routine name'); } $params = ''; $warned_about_dir = false; $warned_about_name = false; $warned_about_length = false; if (!empty($_REQUEST['item_param_name']) && !empty($_REQUEST['item_param_type']) && !empty($_REQUEST['item_param_length']) && is_array($_REQUEST['item_param_name']) && is_array($_REQUEST['item_param_type']) && is_array($_REQUEST['item_param_length'])) { for ($i = 0; $i < count($_REQUEST['item_param_name']); $i++) { if (!empty($_REQUEST['item_param_name'][$i]) && !empty($_REQUEST['item_param_type'][$i])) { if ($_REQUEST['item_type'] == 'PROCEDURE' && !empty($_REQUEST['item_param_dir'][$i]) && in_array($_REQUEST['item_param_dir'][$i], $param_directions)) { $params .= $_REQUEST['item_param_dir'][$i] . " " . PMA_Util::backquote($_REQUEST['item_param_name'][$i]) . " " . $_REQUEST['item_param_type'][$i]; } else { if ($_REQUEST['item_type'] == 'FUNCTION') { $params .= PMA_Util::backquote($_REQUEST['item_param_name'][$i]) . " " . $_REQUEST['item_param_type'][$i]; } else { if (!$warned_about_dir) { $warned_about_dir = true; $errors[] = sprintf(__('Invalid direction "%s" given for parameter.'), htmlspecialchars($_REQUEST['item_param_dir'][$i])); } } } if ($_REQUEST['item_param_length'][$i] != '' && !preg_match('@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT|SERIAL|BOOLEAN)$@i', $_REQUEST['item_param_type'][$i])) { $params .= "(" . $_REQUEST['item_param_length'][$i] . ")"; } else { if ($_REQUEST['item_param_length'][$i] == '' && preg_match('@^(ENUM|SET|VARCHAR|VARBINARY)$@i', $_REQUEST['item_param_type'][$i])) { if (!$warned_about_length) { $warned_about_length = true; $errors[] = __('You must provide length/values for routine parameters of type ENUM, SET, VARCHAR and VARBINARY.'); } } } if (!empty($_REQUEST['item_param_opts_text'][$i])) { if ($GLOBALS['PMA_Types']->getTypeClass($_REQUEST['item_param_type'][$i]) == 'CHAR') { $params .= ' CHARSET ' . strtolower($_REQUEST['item_param_opts_text'][$i]); } } if (!empty($_REQUEST['item_param_opts_num'][$i])) { if ($GLOBALS['PMA_Types']->getTypeClass($_REQUEST['item_param_type'][$i]) == 'NUMBER') { $params .= ' ' . strtoupper($_REQUEST['item_param_opts_num'][$i]); } } if ($i != count($_REQUEST['item_param_name']) - 1) { $params .= ", "; } } else { if (!$warned_about_name) { $warned_about_name = true; $errors[] = __('You must provide a name and a type for each routine parameter.'); break; } } } } $query .= "(" . $params . ") "; if ($_REQUEST['item_type'] == 'FUNCTION') { if (!empty($_REQUEST['item_returntype']) && in_array($_REQUEST['item_returntype'], PMA_Util::getSupportedDatatypes())) { $query .= "RETURNS {$_REQUEST['item_returntype']}"; } else { $errors[] = __('You must provide a valid return type for the routine.'); } if (!empty($_REQUEST['item_returnlength']) && !preg_match('@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT|SERIAL|BOOLEAN)$@i', $_REQUEST['item_returntype'])) { $query .= "(" . $_REQUEST['item_returnlength'] . ")"; } else { if (empty($_REQUEST['item_returnlength']) && preg_match('@^(ENUM|SET|VARCHAR|VARBINARY)$@i', $_REQUEST['item_returntype'])) { if (!$warned_about_length) { $warned_about_length = true; $errors[] = __('You must provide length/values for routine parameters of type ENUM, SET, VARCHAR and VARBINARY.'); } } } if (!empty($_REQUEST['item_returnopts_text'])) { if ($GLOBALS['PMA_Types']->getTypeClass($_REQUEST['item_returntype']) == 'CHAR') { $query .= ' CHARSET ' . strtolower($_REQUEST['item_returnopts_text']); } } if (!empty($_REQUEST['item_returnopts_num'])) { if ($GLOBALS['PMA_Types']->getTypeClass($_REQUEST['item_returntype']) == 'NUMBER') { $query .= ' ' . strtoupper($_REQUEST['item_returnopts_num']); } } $query .= ' '; } if (!empty($_REQUEST['item_comment'])) { $query .= "COMMENT '" . PMA_Util::sqlAddslashes($_REQUEST['item_comment']) . "' "; } if (isset($_REQUEST['item_isdeterministic'])) { $query .= 'DETERMINISTIC '; } else { $query .= 'NOT DETERMINISTIC '; } if (!empty($_REQUEST['item_sqldataaccess']) && in_array($_REQUEST['item_sqldataaccess'], $param_sqldataaccess)) { $query .= $_REQUEST['item_sqldataaccess'] . ' '; } if (!empty($_REQUEST['item_securitytype'])) { if ($_REQUEST['item_securitytype'] == 'DEFINER' || $_REQUEST['item_securitytype'] == 'INVOKER') { $query .= 'SQL SECURITY ' . $_REQUEST['item_securitytype'] . ' '; } } if (!empty($_REQUEST['item_definition'])) { $query .= $_REQUEST['item_definition']; } else { $errors[] = __('You must provide a routine definition.'); } return $query; }
$length = $extracted_columnspec['spec_in_brackets']; } // some types, for example longtext, are reported as // "longtext character set latin7" when their charset and / or collation // differs from the ones of the corresponding database. $tmp = strpos($type, 'character set'); if ($tmp) { $type = substr($type, 0, $tmp - 1); } if (isset($submit_length) && $submit_length != false) { $length = $submit_length; } // rtrim the type, for cases like "float unsigned" $type = rtrim($type); $type_upper = strtoupper($type); $content_cells[$i][$ci] .= PMA_Util::getSupportedDatatypes(true, $type_upper); $content_cells[$i][$ci] .= ' </select>'; $ci++; // old column length if ($is_backup) { $_form_params['field_length_orig[' . $i . ']'] = $length; } // column length $length_to_display = $length; $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"' . ' type="text" name="field_length[' . $i . ']" size="' . $length_values_input_size . '"' . ' value="' . htmlspecialchars($length_to_display) . '"' . ' class="textfield" />' . '<p class="enum_notice" id="enum_notice_' . $i . '_' . ($ci - $ci_offset) . '">'; $content_cells[$i][$ci] .= __('ENUM or SET data too long?') . '<a href="#" class="open_enum_editor"> ' . __('Get more editing space') . '</a>' . '</p>'; $ci++; // column default // old column default if ($is_backup) { $_form_params['field_default_orig[' . $i . ']'] = isset($row['Default']) ? $row['Default'] : '';
/** * Function to get html for the column type * * @param int $columnNumber column number * @param int $ci cell index * @param int $ci_offset cell index offset * @param string $type_upper type inuppercase * @param array $columnMeta meta data * * @return string */ function PMA_getHtmlForColumnType($columnNumber, $ci, $ci_offset, $type_upper, $columnMeta) { $select_id = 'field_' . $columnNumber . '_' . ($ci - $ci_offset); $html = '<select' . (isset($columnMeta['column_status']) && !$columnMeta['column_status']['isEditable'] ? ' disabled="disabled" ' : ' ') . 'class="column_type" name="field_type[' . $columnNumber . ']"' . ' id="' . $select_id . '">'; $html .= PMA_Util::getSupportedDatatypes(true, $type_upper); $html .= ' </select>'; return $html; }
/** * Function to get html for the column type * * @param int $columnNumber column number * @param int $ci cell index * @param int $ci_offset cell index offset * @param string $type_upper type inuppercase * * @return string */ function PMA_getHtmlForColumnType($columnNumber, $ci, $ci_offset, $type_upper) { $select_id = 'field_' . $columnNumber . '_' . ($ci - $ci_offset); $html = '<select class="column_type" name="field_type[' . $columnNumber . ']"' . ' id="' . $select_id . '">'; $html .= PMA_Util::getSupportedDatatypes(true, $type_upper); $html .= ' </select>'; return $html; }