/** * If necessary, prepares routine information and passes * it to PMA_RTE_handleExport() for the actual export. * * @return void */ function PMA_RTN_handleExport() { global $_GET, $db; if (!empty($_GET['export_item']) && !empty($_GET['item_name']) && !empty($_GET['item_type'])) { if ($_GET['item_type'] == 'FUNCTION' || $_GET['item_type'] == 'PROCEDURE') { $export_data = PMA_DBI_get_definition($db, $_GET['item_type'], $_GET['item_name']); PMA_RTE_handleExport($_GET['item_name'], $export_data); } } }
/** * This function will generate the values that are required to complete * the "Edit routine" form given the name of a routine. * * @param string $name The name of the routine. * @param string $type Type of routine (ROUTINE|PROCEDURE) * @param bool $all Whether to return all data or just * the info about parameters. * * @return array Data necessary to create the routine editor. */ function PMA_RTN_getDataFromName($name, $type, $all = true) { global $db; $retval = array(); // Build and execute the query $fields = "SPECIFIC_NAME, ROUTINE_TYPE, DTD_IDENTIFIER, " . "ROUTINE_DEFINITION, IS_DETERMINISTIC, SQL_DATA_ACCESS, " . "ROUTINE_COMMENT, SECURITY_TYPE"; $where = "ROUTINE_SCHEMA='" . PMA_Util::sqlAddSlashes($db) . "' " . "AND SPECIFIC_NAME='" . PMA_Util::sqlAddSlashes($name) . "'" . "AND ROUTINE_TYPE='" . PMA_Util::sqlAddSlashes($type) . "'"; $query = "SELECT {$fields} FROM INFORMATION_SCHEMA.ROUTINES WHERE {$where};"; $routine = PMA_DBI_fetch_single_row($query); if (!$routine) { return false; } // Get required data $retval['item_name'] = $routine['SPECIFIC_NAME']; $retval['item_type'] = $routine['ROUTINE_TYPE']; $parsed_query = PMA_SQP_parse(PMA_DBI_get_definition($db, $routine['ROUTINE_TYPE'], $routine['SPECIFIC_NAME'])); $params = PMA_RTN_parseAllParameters($parsed_query, $routine['ROUTINE_TYPE']); $retval['item_num_params'] = $params['num']; $retval['item_param_dir'] = $params['dir']; $retval['item_param_name'] = $params['name']; $retval['item_param_type'] = $params['type']; $retval['item_param_length'] = $params['length']; $retval['item_param_opts_num'] = $params['opts']; $retval['item_param_opts_text'] = $params['opts']; // Get extra data if ($all) { if ($retval['item_type'] == 'FUNCTION') { $retval['item_type_toggle'] = 'PROCEDURE'; } else { $retval['item_type_toggle'] = 'FUNCTION'; } $retval['item_returntype'] = ''; $retval['item_returnlength'] = ''; $retval['item_returnopts_num'] = ''; $retval['item_returnopts_text'] = ''; if (!empty($routine['DTD_IDENTIFIER'])) { if (strlen($routine['DTD_IDENTIFIER']) > 63) { // If the DTD_IDENTIFIER string from INFORMATION_SCHEMA is // at least 64 characters, then it may actually have been // chopped because that column is a varchar(64), so we will // parse the output of SHOW CREATE query to get accurate // information about the return variable. $dtd = ''; $fetching = false; for ($i = 0; $i < $parsed_query['len']; $i++) { if ($parsed_query[$i]['type'] == 'alpha_reservedWord' && strtoupper($parsed_query[$i]['data']) == 'RETURNS') { $fetching = true; } else { if ($fetching == true && $parsed_query[$i]['type'] == 'alpha_reservedWord') { // We will not be looking for options such as UNSIGNED // or ZEROFILL because there is no way that a numeric // field's DTD_IDENTIFIER can be longer than 64 // characters. We can safely assume that the return // datatype is either ENUM or SET, so we only look // for CHARSET. $word = strtoupper($parsed_query[$i]['data']); if ($word == 'CHARSET' && ($parsed_query[$i + 1]['type'] == 'alpha_charset' || $parsed_query[$i + 1]['type'] == 'alpha_identifier')) { $dtd .= $word . ' ' . $parsed_query[$i + 1]['data']; } break; } else { if ($fetching == true) { $dtd .= $parsed_query[$i]['data'] . ' '; } } } } $routine['DTD_IDENTIFIER'] = $dtd; } $returnparam = PMA_RTN_parseOneParameter($routine['DTD_IDENTIFIER']); $retval['item_returntype'] = $returnparam[2]; $retval['item_returnlength'] = $returnparam[3]; $retval['item_returnopts_num'] = $returnparam[4]; $retval['item_returnopts_text'] = $returnparam[4]; } $retval['item_definer'] = PMA_RTN_parseRoutineDefiner($parsed_query); $retval['item_definition'] = $routine['ROUTINE_DEFINITION']; $retval['item_isdeterministic'] = ''; if ($routine['IS_DETERMINISTIC'] == 'YES') { $retval['item_isdeterministic'] = " checked='checked'"; } $retval['item_securitytype_definer'] = ''; $retval['item_securitytype_invoker'] = ''; if ($routine['SECURITY_TYPE'] == 'DEFINER') { $retval['item_securitytype_definer'] = " selected='selected'"; } else { if ($routine['SECURITY_TYPE'] == 'INVOKER') { $retval['item_securitytype_invoker'] = " selected='selected'"; } } $retval['item_sqldataaccess'] = $routine['SQL_DATA_ACCESS']; $retval['item_comment'] = $routine['ROUTINE_COMMENT']; } return $retval; }
echo '<table border="0">'; echo sprintf('<tr> <th>%s</th> <th> </th> <th> </th> <th>%s</th> <th>%s</th> </tr>', $strName, $strType, $strRoutineReturnType); $ct = 0; $delimiter = '//'; 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 $definition = 'DROP ' . $routine['ROUTINE_TYPE'] . ' ' . PMA_backquote($routine['SPECIFIC_NAME']) . $delimiter . "\n" . PMA_DBI_get_definition($db, $routine['ROUTINE_TYPE'], $routine['SPECIFIC_NAME']) . "\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 ' . PMA_backquote($routine['SPECIFIC_NAME']); } else { $sqlDropProc = 'DROP FUNCTION ' . PMA_backquote($routine['SPECIFIC_NAME']);
$procedure_names = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE'); if ($procedure_names) { foreach ($procedure_names as $procedure_name) { PMA_DBI_select_db($db); $tmp_query = PMA_DBI_get_definition($db, 'PROCEDURE', $procedure_name); // collect for later display $GLOBALS['sql_query'] .= "\n" . $tmp_query; PMA_DBI_select_db($newname); PMA_DBI_query($tmp_query); } } $function_names = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION'); if ($function_names) { foreach ($function_names as $function_name) { PMA_DBI_select_db($db); $tmp_query = PMA_DBI_get_definition($db, 'FUNCTION', $function_name); // collect for later display $GLOBALS['sql_query'] .= "\n" . $tmp_query; PMA_DBI_select_db($newname); PMA_DBI_query($tmp_query); } } } // go back to current db, just in case PMA_DBI_select_db($db); // Duplicate the bookmarks for this db (done once for each db) if (!$_error && $db != $newname) { $get_fields = array('user', 'label', 'query'); $where_fields = array('dbase' => $db); $new_fields = array('dbase' => $newname); PMA_Table::duplicateInfo('bookmarkwork', 'bookmark', $get_fields, $where_fields, $new_fields);
/** * Outputs database footer * * @param string $db Database name * * @return bool Whether it succeeded */ public function exportDBFooter($db) { global $crlf; $result = true; if (isset($GLOBALS['sql_constraints'])) { $result = PMA_exportOutputHandler($GLOBALS['sql_constraints']); unset($GLOBALS['sql_constraints']); } if (($GLOBALS['sql_structure_or_data'] == 'structure' || $GLOBALS['sql_structure_or_data'] == 'structure_and_data') && isset($GLOBALS['sql_procedure_function'])) { $text = ''; $delimiter = '$$'; if (PMA_MYSQL_INT_VERSION > 50100) { $event_names = PMA_DBI_fetch_result('SELECT EVENT_NAME FROM information_schema.EVENTS WHERE' . ' EVENT_SCHEMA= \'' . PMA_Util::sqlAddSlashes($db, true) . '\';'); } else { $event_names = array(); } if ($event_names) { $text .= $crlf . 'DELIMITER ' . $delimiter . $crlf; $text .= $this->_exportComment() . $this->_exportComment(__('Events')) . $this->_exportComment(); foreach ($event_names as $event_name) { if (!empty($GLOBALS['sql_drop_table'])) { $text .= 'DROP EVENT ' . PMA_Util::backquote($event_name) . $delimiter . $crlf; } $text .= PMA_DBI_get_definition($db, 'EVENT', $event_name) . $delimiter . $crlf . $crlf; } $text .= 'DELIMITER ;' . $crlf; } if (!empty($text)) { $result = PMA_exportOutputHandler($text); } } return $result; }
// and prepare to display them $GLOBALS['sql_query'] .= "\n" . $one_query; } unset($GLOBALS['sql_constraints_query_full_db'], $one_query); } if (!PMA_DRIZZLE && PMA_MYSQL_INT_VERSION >= 50100) { // here DELIMITER is not used because it's not part of the // language; each statement is sent one by one // to avoid selecting alternatively the current and new db // we would need to modify the CREATE definitions to qualify // the db name $event_names = PMA_DBI_fetch_result('SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \'' . PMA_sqlAddSlashes($db, true) . '\';'); if ($event_names) { foreach ($event_names as $event_name) { PMA_DBI_select_db($db); $tmp_query = PMA_DBI_get_definition($db, 'EVENT', $event_name); // collect for later display $GLOBALS['sql_query'] .= "\n" . $tmp_query; PMA_DBI_select_db($newname); PMA_DBI_query($tmp_query); } } } // go back to current db, just in case PMA_DBI_select_db($db); // Duplicate the bookmarks for this db (done once for each db) if (!$_error && $db != $newname) { $get_fields = array('user', 'label', 'query'); $where_fields = array('dbase' => $db); $new_fields = array('dbase' => $newname); PMA_Table::duplicateInfo('bookmarkwork', 'bookmark', $get_fields, $where_fields, $new_fields);
/** * Outputs export header * * @return bool Whether it suceeded * * @access public */ function PMA_exportHeader() { global $crlf; global $cfg; global $what; global $db; global $table; global $tables; $export_struct = isset($GLOBALS[$what . '_export_struc']) ? true : false; $export_data = isset($GLOBALS[$what . '_export_contents']) ? true : false; if ($GLOBALS['output_charset_conversion']) { $charset = $GLOBALS['charset_of_file']; } else { $charset = $GLOBALS['charset']; } $head = '<?xml version="1.0" encoding="' . $charset . '"?>' . $crlf . '<!--' . $crlf . '- phpMyAdmin XML Dump' . $crlf . '- version ' . PMA_VERSION . $crlf . '- http://www.phpmyadmin.net' . $crlf . '-' . $crlf . '- ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host']; if (!empty($cfg['Server']['port'])) { $head .= ':' . $cfg['Server']['port']; } $head .= $crlf . '- ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf . '- ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf . '- ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf . '-->' . $crlf . $crlf; $head .= '<pma_xml_export version="1.0"' . ($export_struct ? ' xmlns:pma="http://www.phpmyadmin.net/some_doc_url/"' : '') . '>' . $crlf; if ($export_struct) { $result = PMA_DBI_fetch_result('SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME` FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME` = \'' . $db . '\' LIMIT 1'); $db_collation = $result[0]['DEFAULT_COLLATION_NAME']; $db_charset = $result[0]['DEFAULT_CHARACTER_SET_NAME']; $head .= ' <!--' . $crlf; $head .= ' - Structure schemas' . $crlf; $head .= ' -->' . $crlf; $head .= ' <pma:structure_schemas>' . $crlf; $head .= ' <pma:database name="' . $db . '" collation="' . $db_collation . '" charset="' . $db_charset . '">' . $crlf; if (count($tables) == 0) { $tables[] = $table; } foreach ($tables as $table) { // Export tables and views $result = PMA_DBI_fetch_result('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), 0); $tbl = $result[$table][1]; $is_view = PMA_isView($db, $table); if ($is_view) { $type = 'view'; } else { $type = 'table'; } if ($is_view && !isset($GLOBALS[$what . '_export_views'])) { continue; } if (!$is_view && !isset($GLOBALS[$what . '_export_tables'])) { continue; } $head .= ' <pma:' . $type . ' name="' . $table . '">' . $crlf; $tbl = " " . $tbl; $tbl = str_replace("\n", "\n ", $tbl); $head .= $tbl . ';' . $crlf; $head .= ' </pma:' . $type . '>' . $crlf; if (isset($GLOBALS[$what . '_export_triggers']) && $GLOBALS[$what . '_export_triggers']) { // Export triggers $triggers = PMA_DBI_get_triggers($db, $table); if ($triggers) { foreach ($triggers as $trigger) { $code = $trigger['create']; $head .= ' <pma:trigger name="' . $trigger['name'] . '">' . $crlf; // Do some formatting $code = substr(rtrim($code), 0, -3); $code = " " . $code; $code = str_replace("\n", "\n ", $code); $head .= $code . $crlf; $head .= ' </pma:trigger>' . $crlf; } unset($trigger); unset($triggers); } } } if (isset($GLOBALS[$what . '_export_functions']) && $GLOBALS[$what . '_export_functions']) { // Export functions $functions = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION'); if ($functions) { foreach ($functions as $function) { $head .= ' <pma:function name="' . $function . '">' . $crlf; // Do some formatting $sql = PMA_DBI_get_definition($db, 'FUNCTION', $function); $sql = rtrim($sql); $sql = " " . $sql; $sql = str_replace("\n", "\n ", $sql); $head .= $sql . $crlf; $head .= ' </pma:function>' . $crlf; } unset($create_func); unset($function); unset($functions); } } if (isset($GLOBALS[$what . '_export_procedures']) && $GLOBALS[$what . '_export_procedures']) { // Export procedures $procedures = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE'); if ($procedures) { foreach ($procedures as $procedure) { $head .= ' <pma:procedure name="' . $procedure . '">' . $crlf; // Do some formatting $sql = PMA_DBI_get_definition($db, 'PROCEDURE', $procedure); $sql = rtrim($sql); $sql = " " . $sql; $sql = str_replace("\n", "\n ", $sql); $head .= $sql . $crlf; $head .= ' </pma:procedure>' . $crlf; } unset($create_proc); unset($procedure); unset($procedures); } } unset($result); $head .= ' </pma:database>' . $crlf; $head .= ' </pma:structure_schemas>' . $crlf; if ($export_data) { $head .= $crlf; } } return PMA_exportOutputHandler($head); }
/** * Outputs export header. It is the first method to be called, so all * the required variables are initialized here. * * @return bool Whether it succeeded */ public function exportHeader() { $this->initSpecificVariables(); global $crlf, $cfg, $db; $table = $this->_getTable(); $tables = $this->_getTables(); $export_struct = isset($GLOBALS['xml_export_functions']) || isset($GLOBALS['xml_export_procedures']) || isset($GLOBALS['xml_export_tables']) || isset($GLOBALS['xml_export_triggers']) || isset($GLOBALS['xml_export_views']); $export_data = isset($GLOBALS['xml_export_contents']) ? true : false; if ($GLOBALS['output_charset_conversion']) { $charset = $GLOBALS['charset_of_file']; } else { $charset = 'utf-8'; } $head = '<?xml version="1.0" encoding="' . $charset . '"?>' . $crlf . '<!--' . $crlf . '- phpMyAdmin XML Dump' . $crlf . '- version ' . PMA_VERSION . $crlf . '- http://www.phpmyadmin.net' . $crlf . '-' . $crlf . '- ' . __('Host') . ': ' . $cfg['Server']['host']; if (!empty($cfg['Server']['port'])) { $head .= ':' . $cfg['Server']['port']; } $head .= $crlf . '- ' . __('Generation Time') . ': ' . PMA_Util::localisedDate() . $crlf . '- ' . __('Server version') . ': ' . PMA_MYSQL_STR_VERSION . $crlf . '- ' . __('PHP Version') . ': ' . phpversion() . $crlf . '-->' . $crlf . $crlf; $head .= '<pma_xml_export version="1.0"' . ($export_struct ? ' xmlns:pma="http://www.phpmyadmin.net/some_doc_url/"' : '') . '>' . $crlf; if ($export_struct) { if (PMA_DRIZZLE) { $result = PMA_DBI_fetch_result("SELECT\n 'utf8' AS DEFAULT_CHARACTER_SET_NAME,\n DEFAULT_COLLATION_NAME\n FROM data_dictionary.SCHEMAS\n WHERE SCHEMA_NAME = '" . PMA_Util::sqlAddSlashes($db) . "'"); } else { $result = PMA_DBI_fetch_result('SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`' . ' FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`' . ' = \'' . PMA_Util::sqlAddSlashes($db) . '\' LIMIT 1'); } $db_collation = $result[0]['DEFAULT_COLLATION_NAME']; $db_charset = $result[0]['DEFAULT_CHARACTER_SET_NAME']; $head .= ' <!--' . $crlf; $head .= ' - Structure schemas' . $crlf; $head .= ' -->' . $crlf; $head .= ' <pma:structure_schemas>' . $crlf; $head .= ' <pma:database name="' . htmlspecialchars($db) . '" collation="' . $db_collation . '" charset="' . $db_charset . '">' . $crlf; if (count($tables) == 0) { $tables[] = $table; } foreach ($tables as $table) { // Export tables and views $result = PMA_DBI_fetch_result('SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0); $tbl = $result[$table][1]; $is_view = PMA_Table::isView($db, $table); if ($is_view) { $type = 'view'; } else { $type = 'table'; } if ($is_view && !isset($GLOBALS['xml_export_views'])) { continue; } if (!$is_view && !isset($GLOBALS['xml_export_tables'])) { continue; } $head .= ' <pma:' . $type . ' name="' . $table . '">' . $crlf; $tbl = " " . htmlspecialchars($tbl); $tbl = str_replace("\n", "\n ", $tbl); $head .= $tbl . ';' . $crlf; $head .= ' </pma:' . $type . '>' . $crlf; if (isset($GLOBALS['xml_export_triggers']) && $GLOBALS['xml_export_triggers']) { // Export triggers $triggers = PMA_DBI_get_triggers($db, $table); if ($triggers) { foreach ($triggers as $trigger) { $code = $trigger['create']; $head .= ' <pma:trigger name="' . $trigger['name'] . '">' . $crlf; // Do some formatting $code = substr(rtrim($code), 0, -3); $code = " " . htmlspecialchars($code); $code = str_replace("\n", "\n ", $code); $head .= $code . $crlf; $head .= ' </pma:trigger>' . $crlf; } unset($trigger); unset($triggers); } } } if (isset($GLOBALS['xml_export_functions']) && $GLOBALS['xml_export_functions']) { // Export functions $functions = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION'); if ($functions) { foreach ($functions as $function) { $head .= ' <pma:function name="' . $function . '">' . $crlf; // Do some formatting $sql = PMA_DBI_get_definition($db, 'FUNCTION', $function); $sql = rtrim($sql); $sql = " " . htmlspecialchars($sql); $sql = str_replace("\n", "\n ", $sql); $head .= $sql . $crlf; $head .= ' </pma:function>' . $crlf; } unset($function); unset($functions); } } if (isset($GLOBALS['xml_export_procedures']) && $GLOBALS['xml_export_procedures']) { // Export procedures $procedures = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE'); if ($procedures) { foreach ($procedures as $procedure) { $head .= ' <pma:procedure name="' . $procedure . '">' . $crlf; // Do some formatting $sql = PMA_DBI_get_definition($db, 'PROCEDURE', $procedure); $sql = rtrim($sql); $sql = " " . htmlspecialchars($sql); $sql = str_replace("\n", "\n ", $sql); $head .= $sql . $crlf; $head .= ' </pma:procedure>' . $crlf; } unset($procedure); unset($procedures); } } unset($result); $head .= ' </pma:database>' . $crlf; $head .= ' </pma:structure_schemas>' . $crlf; if ($export_data) { $head .= $crlf; } } return PMA_exportOutputHandler($head); }
/** * Handles editor requests for adding or editing an item */ function PMA_EVN_handleEditor() { global $_REQUEST, $_POST, $errors, $db; if (!empty($_REQUEST['editor_process_add']) || !empty($_REQUEST['editor_process_edit'])) { $sql_query = ''; $item_query = PMA_EVN_getQueryFromRequest(); if (!count($errors)) { // set by PMA_RTN_getQueryFromRequest() // Execute the created query if (!empty($_REQUEST['editor_process_edit'])) { // Backup the old trigger, in case something goes wrong $create_item = PMA_DBI_get_definition($db, 'EVENT', $_REQUEST['item_original_name']); $drop_item = "DROP EVENT " . PMA_backquote($_REQUEST['item_original_name']) . ";\n"; $result = PMA_DBI_try_query($drop_item); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), $drop_item) . '<br />' . __('MySQL said: ') . PMA_DBI_getError(null); } else { $result = PMA_DBI_try_query($item_query); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), $item_query) . '<br />' . __('MySQL said: ') . PMA_DBI_getError(null); // We dropped the old item, but were unable to create the new one // Try to restore the backup query $result = PMA_DBI_try_query($create_item); if (!$result) { // OMG, this is really bad! We dropped the query, failed to create a new one // and now even the backup query does not execute! // This should not happen, but we better handle this just in case. $errors[] = __('Sorry, we failed to restore the dropped event.') . '<br />' . __('The backed up query was:') . "\"{$create_item}\"" . '<br />' . __('MySQL said: ') . PMA_DBI_getError(null); } } else { $message = PMA_Message::success(__('Event %1$s has been modified.')); $message->addParam(PMA_backquote($_REQUEST['item_name'])); $sql_query = $drop_item . $item_query; } } } else { // 'Add a new item' mode $result = PMA_DBI_try_query($item_query); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), $item_query) . '<br /><br />' . __('MySQL said: ') . PMA_DBI_getError(null); } else { $message = PMA_Message::success(__('Event %1$s has been created.')); $message->addParam(PMA_backquote($_REQUEST['item_name'])); $sql_query = $item_query; } } } if (count($errors)) { $message = PMA_Message::error(__('<b>One or more errors have occured while processing your request:</b>')); $message->addString('<ul>'); foreach ($errors as $string) { $message->addString('<li>' . $string . '</li>'); } $message->addString('</ul>'); } $output = PMA_showMessage($message, $sql_query); if ($GLOBALS['is_ajax_request']) { $extra_data = array(); if ($message->isSuccess()) { $columns = "`EVENT_NAME`, `EVENT_TYPE`, `STATUS`"; $where = "EVENT_SCHEMA='" . PMA_sqlAddSlashes($db) . "' " . "AND EVENT_NAME='" . PMA_sqlAddSlashes($_REQUEST['item_name']) . "'"; $query = "SELECT {$columns} FROM `INFORMATION_SCHEMA`.`EVENTS` WHERE {$where};"; $event = PMA_DBI_fetch_single_row($query); $extra_data['name'] = htmlspecialchars(strtoupper($_REQUEST['item_name'])); $extra_data['new_row'] = PMA_EVN_getRowForList($event); $extra_data['insert'] = !empty($event); $response = $output; } else { $response = $message; } PMA_ajaxResponse($response, $message->isSuccess(), $extra_data); } } /** * Display a form used to add/edit a trigger, if necessary */ if (count($errors) || empty($_REQUEST['editor_process_add']) && empty($_REQUEST['editor_process_edit']) && (!empty($_REQUEST['add_item']) || !empty($_REQUEST['edit_item']) || !empty($_REQUEST['item_changetype']))) { // FIXME: this must be simpler than that $operation = ''; if (!empty($_REQUEST['item_changetype'])) { $operation = 'change'; } // Get the data for the form (if any) if (!empty($_REQUEST['add_item'])) { $title = PMA_RTE_getWord('add'); $item = PMA_EVN_getDataFromRequest(); $mode = 'add'; } else { if (!empty($_REQUEST['edit_item'])) { $title = __("Edit event"); if (!empty($_REQUEST['item_name']) && empty($_REQUEST['editor_process_edit']) && empty($_REQUEST['item_changetype'])) { $item = PMA_EVN_getDataFromName($_REQUEST['item_name']); if ($item !== false) { $item['item_original_name'] = $item['item_name']; } } else { $item = PMA_EVN_getDataFromRequest(); } $mode = 'edit'; } } if ($item !== false) { // Show form $editor = PMA_EVN_getEditorForm($mode, $operation, $item); if ($GLOBALS['is_ajax_request']) { $extra_data = array('title' => $title); PMA_ajaxResponse($editor, true, $extra_data); } else { echo "\n\n<h2>{$title}</h2>\n\n{$editor}"; unset($_POST); include './libraries/footer.inc.php'; } // exit; } else { $message = __('Error in processing request') . ' : '; $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_backquote($db))); $message = PMA_message::error($message); if ($GLOBALS['is_ajax_request']) { PMA_ajaxResponse($message, false); } else { $message->display(); } } } }
/** * Outputs database footer * * @param string Database name * * @return bool Whether it suceeded * * @access public */ function PMA_exportDBFooter($db) { global $crlf; $result = TRUE; if (isset($GLOBALS['sql_constraints'])) { $result = PMA_exportOutputHandler($GLOBALS['sql_constraints']); unset($GLOBALS['sql_constraints']); } if (isset($GLOBALS['sql_structure']) && isset($GLOBALS['sql_procedure_function'])) { $text = ''; $delimiter = '$$'; $procedure_names = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE'); $function_names = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION'); if (PMA_MYSQL_INT_VERSION > 50100) { $event_names = PMA_DBI_fetch_result('SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \'' . PMA_sqlAddslashes($db, true) . '\';'); } else { $event_names = array(); } if ($procedure_names || $function_names || $event_names) { $text .= $crlf . 'DELIMITER ' . $delimiter . $crlf; } if ($procedure_names) { $text .= PMA_exportComment() . PMA_exportComment($GLOBALS['strProcedures']) . PMA_exportComment(); foreach ($procedure_names as $procedure_name) { if (!empty($GLOBALS['sql_drop_table'])) { $text .= 'DROP PROCEDURE IF EXISTS ' . PMA_backquote($procedure_name) . $delimiter . $crlf; } $text .= PMA_DBI_get_definition($db, 'PROCEDURE', $procedure_name) . $delimiter . $crlf . $crlf; } } if ($function_names) { $text .= PMA_exportComment() . PMA_exportComment($GLOBALS['strFunctions']) . PMA_exportComment(); foreach ($function_names as $function_name) { if (!empty($GLOBALS['sql_drop_table'])) { $text .= 'DROP FUNCTION IF EXISTS ' . PMA_backquote($function_name) . $delimiter . $crlf; } $text .= PMA_DBI_get_definition($db, 'FUNCTION', $function_name) . $delimiter . $crlf . $crlf; } } if ($event_names) { $text .= PMA_exportComment() . PMA_exportComment($GLOBALS['strEvents']) . PMA_exportComment(); foreach ($event_names as $event_name) { if (!empty($GLOBALS['sql_drop_table'])) { $text .= 'DROP EVENT ' . PMA_backquote($event_name) . $delimiter . $crlf; } $text .= PMA_DBI_get_definition($db, 'EVENT', $event_name) . $delimiter . $crlf . $crlf; } } if ($procedure_names || $function_names || $event_names) { $text .= 'DELIMITER ;' . $crlf; } if (!empty($text)) { $result = PMA_exportOutputHandler($text); } } return $result; }
if ($events) { PMA_generate_slider_effect('events', $strEvents); echo '<fieldset>' . "\n"; echo ' <legend>' . $strEvents . '</legend>' . "\n"; echo '<table border="0">'; echo sprintf('<tr> <th>%s</th> <th> </th> <th> </th> <th>%s</th> </tr>', $strName, $strType); $ct = 0; $delimiter = '//'; foreach ($events as $event) { // information_schema (at least in MySQL 5.1.22) does not return // the full CREATE EVENT statement in a way that could be useful for us // so we rely on PMA_DBI_get_definition() which uses SHOW CREATE EVENT $definition = 'DROP EVENT ' . PMA_backquote($event['EVENT_NAME']) . $delimiter . "\n" . PMA_DBI_get_definition($db, 'EVENT', $event['EVENT_NAME']) . "\n"; $sqlDrop = 'DROP EVENT ' . PMA_backquote($event['EVENT_NAME']); echo sprintf('<tr class="%s"> <td><strong>%s</strong></td> <td>%s</td> <td>%s</td> <td>%s</td> </tr>', $ct % 2 == 0 ? 'even' : 'odd', $event['EVENT_NAME'], !empty($definition) ? PMA_linkOrButton('db_sql.php?' . $url_query . '&sql_query=' . urlencode($definition) . '&show_query=1&delimiter=' . urlencode($delimiter), $titles['Structure']) : ' ', '<a href="sql.php?' . $url_query . '&sql_query=' . urlencode($sqlDrop) . '" onclick="return confirmLink(this, \'' . PMA_jsFormat($sqlDrop, false) . '\')">' . $titles['Drop'] . '</a>', $event['EVENT_TYPE']); $ct++; } echo '</table>'; echo '</fieldset>' . "\n"; echo '</div>' . "\n"; }
/** * Get HTML for edit views' * * @param string $url_params URL parameters * * @return string $html_output */ function PMA_getHtmlForEditView($url_params) { $create_view = PMA_DBI_get_definition($GLOBALS['db'], 'VIEW', $GLOBALS['table']); $create_view = preg_replace('@^CREATE@', 'ALTER', $create_view); $html_output = PMA_Util::linkOrButton('tbl_sql.php' . PMA_generate_common_url($url_params + array('sql_query' => $create_view, 'show_query' => '1')), PMA_Util::getIcon('b_edit.png', __('Edit view'), true)); return $html_output; }
PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_spatial', __('Spatial'), 'b_spatial.png', 'spatial'); } if (!empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA')) { PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_fulltext', __('Fulltext'), 'b_ftext.png', 'ftext'); } } ?> </form> <hr /> <?php /** * Work on the table */ if ($tbl_is_view) { $create_view = PMA_DBI_get_definition($db, 'VIEW', $table); $create_view = preg_replace('@^CREATE@', 'ALTER', $create_view); echo PMA_linkOrButton('tbl_sql.php' . PMA_generate_common_url($url_params + array('sql_query' => $create_view, 'show_query' => '1')), PMA_getIcon('b_edit.png', __('Edit view'), true)); } ?> <a href="tbl_printview.php?<?php echo $url_query; ?> "><?php echo PMA_getIcon('b_print.png', __('Print view'), true); ?> </a> <?php if (!$tbl_is_view && !$db_is_information_schema) {
/** * Run the EVENT definition for selected database * * to avoid selecting alternatively the current and new db * we would need to modify the CREATE definitions to qualify * the db name * * @param string $db database name * * @return void */ function PMA_runEventDefinitionsForDb($db) { $event_names = PMA_DBI_fetch_result('SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \'' . PMA_Util::sqlAddSlashes($db, true) . '\';'); if ($event_names) { foreach ($event_names as $event_name) { PMA_DBI_select_db($db); $tmp_query = PMA_DBI_get_definition($db, 'EVENT', $event_name); // collect for later display $GLOBALS['sql_query'] .= "\n" . $tmp_query; PMA_DBI_select_db($_REQUEST['newname']); PMA_DBI_query($tmp_query); } } }
<th> </th> <th> </th> <th>%s</th> </tr>', $strName, $strType); $ct=0; $delimiter = '//'; foreach ($events as $event) { // information_schema (at least in MySQL 5.1.22) does not return // the full CREATE EVENT statement in a way that could be useful for us // so we rely on PMA_DBI_get_definition() which uses SHOW CREATE EVENT $definition = 'DROP EVENT ' . PMA_backquote($event['EVENT_NAME']) . $delimiter . "\n" . PMA_DBI_get_definition($db, 'EVENT', $event['EVENT_NAME']) . "\n"; $sqlDrop = 'DROP EVENT ' . PMA_backquote($event['EVENT_NAME']); echo sprintf('<tr class="%s"> <td><strong>%s</strong></td> <td>%s</td> <td>%s</td> <td>%s</td> </tr>', ($ct%2 == 0) ? 'even' : 'odd', $event['EVENT_NAME'], ! empty($definition) ? PMA_linkOrButton('db_sql.php?' . $url_query . '&sql_query=' . urlencode($definition) . '&show_query=1&delimiter=' . urlencode($delimiter), $titles['Structure']) : ' ', '<a href="sql.php?' . $url_query . '&sql_query=' . urlencode($sqlDrop) . '" onclick="return confirmLink(this, \'' . PMA_jsFormat($sqlDrop, false) . '\')">' . $titles['Drop'] . '</a>', $event['EVENT_TYPE']); $ct++;
<th>%s</th> </tr>', $strName, $strType, $strRoutineReturnType); $ct=0; $delimiter = '//'; 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 $definition = 'DROP ' . $routine['ROUTINE_TYPE'] . ' ' . PMA_backquote($routine['SPECIFIC_NAME']) . $delimiter . "\n" . PMA_DBI_get_definition($db, $routine['ROUTINE_TYPE'], $routine['SPECIFIC_NAME']) . "\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 ' . PMA_backquote($routine['SPECIFIC_NAME']);