From 1484ca6c00d132f2215d25d8fd71d026fbb4701c Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 13 Feb 2011 14:00:14 -0500 Subject: [PATCH] Procedures and functions should be exported also when entering Export on a single db --- export.php | 9 ++++ libraries/export/sql.php | 108 ++++++++++++++++++++++----------------- 2 files changed, 69 insertions(+), 48 deletions(-) diff --git a/export.php b/export.php index 26154962e..7da25fc05 100644 --- a/export.php +++ b/export.php @@ -458,6 +458,10 @@ if ($export_type == 'server') { if (!PMA_exportDBCreate($current_db)) { break 2; } + if (function_exists('PMA_exportRoutines') && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false && isset($GLOBALS['sql_procedure_function'])) { + PMA_exportRoutines($current_db); + } + $tables = PMA_DBI_get_tables($current_db); $views = array(); foreach ($tables as $table) { @@ -506,6 +510,11 @@ if ($export_type == 'server') { if (!PMA_exportDBHeader($db)) { break; } + + if (function_exists('PMA_exportRoutines') && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false && isset($GLOBALS['sql_procedure_function'])) { + PMA_exportRoutines($db); + } + $i = 0; $views = array(); // $tables contains the choices from the user (via $table_select) diff --git a/libraries/export/sql.php b/libraries/export/sql.php index 677eac5ea..778662c8c 100644 --- a/libraries/export/sql.php +++ b/libraries/export/sql.php @@ -182,6 +182,66 @@ if (! isset($sql_backquotes)) { $sql_backquotes = null; } +/** + * Exports routines (procedures and functions) + * + * @param string $db + * + * @return bool Whether it suceeded + */ +function PMA_exportRoutines($db) { + global $crlf; + + $text = ''; + $delimiter = '$$'; + + $procedure_names = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE'); + $function_names = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION'); + + if ($procedure_names || $function_names) { + $text .= $crlf + . 'DELIMITER ' . $delimiter . $crlf; + } + + if ($procedure_names) { + $text .= + PMA_exportComment() + . PMA_exportComment(__('Procedures')) + . 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(__('Functions')) + . 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 ($procedure_names || $function_names) { + $text .= 'DELIMITER ;' . $crlf; + } + + if (! empty($text)) { + return PMA_exportOutputHandler($text); + } else { + return false; + } +} + /** * Possibly outputs comment * @@ -375,54 +435,6 @@ function PMA_exportDBCreate($db) $result = PMA_exportOutputHandler('USE ' . $db . ';' . $crlf); } - if ($result && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false && 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 ($procedure_names || $function_names) { - $text .= $crlf - . 'DELIMITER ' . $delimiter . $crlf; - } - - if ($procedure_names) { - $text .= - PMA_exportComment() - . PMA_exportComment(__('Procedures')) - . 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(__('Functions')) - . 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 ($procedure_names || $function_names) { - $text .= 'DELIMITER ;' . $crlf; - } - - if (! empty($text)) { - $result = PMA_exportOutputHandler($text); - } - } return $result; }