Skip to content

Commit

Permalink
export/copy procedures and routines before tables
Browse files Browse the repository at this point in the history
  • Loading branch information
ruleant committed Sep 28, 2010
1 parent c812a4b commit c0d1c7a
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 72 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -8,6 +8,8 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA
3.3.8.0 (not yet released)
- bug #3059311 [import] BIGINT field type added to table analysis
- [core] Update library PHPExcel to version 1.7.4
- bug #3062455 [core] copy procedures and routines before tables
- bug #3062455 [export] with SQL, export procedures and routines before tables

3.3.7.0 (2010-09-07)
- patch #3050492 [PDF scratchboard] Cannot drag table box to the edge after
Expand Down
68 changes: 34 additions & 34 deletions db_operations.php
Expand Up @@ -66,6 +66,40 @@
$GLOBALS['pma']->databases->build();
}

if (PMA_MYSQL_INT_VERSION >= 50000) {
// here I don't use DELIMITER because it's not part of the
// language; I have to send each statement 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
$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);

if (isset($GLOBALS['add_constraints']) || $move) {
$GLOBALS['sql_constraints_query_full_db'] = array();
}
Expand Down Expand Up @@ -178,40 +212,6 @@
unset($GLOBALS['sql_constraints_query_full_db'], $one_query);
}

if (PMA_MYSQL_INT_VERSION >= 50000) {
// here I don't use DELIMITER because it's not part of the
// language; I have to send each statement 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
$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');
Expand Down
93 changes: 55 additions & 38 deletions libraries/export/sql.php
Expand Up @@ -307,9 +307,60 @@ function PMA_exportDBCreate($db)
return FALSE;
}
if (isset($GLOBALS['sql_backquotes']) && isset($GLOBALS['sql_compatibility']) && $GLOBALS['sql_compatibility'] == 'NONE') {
return PMA_exportOutputHandler('USE ' . PMA_backquote($db) . ';' . $crlf);
$result = PMA_exportOutputHandler('USE ' . PMA_backquote($db) . ';' . $crlf);
} else {
$result = PMA_exportOutputHandler('USE ' . $db . ';' . $crlf);
}

if ($result && 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 ($procedure_names || $function_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 ($procedure_names || $function_names) {
$text .= 'DELIMITER ;' . $crlf;
}

if (! empty($text)) {
$result = PMA_exportOutputHandler($text);
}
}
return PMA_exportOutputHandler('USE ' . $db . ';' . $crlf);
return $result;
}

/**
Expand Down Expand Up @@ -352,49 +403,16 @@ function PMA_exportDBFooter($db)
$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) {
if ($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'])
Expand All @@ -406,8 +424,7 @@ function PMA_exportDBFooter($db)
}
$text .= PMA_DBI_get_definition($db, 'EVENT', $event_name) . $delimiter . $crlf . $crlf;
}
}
if ($procedure_names || $function_names || $event_names) {

$text .= 'DELIMITER ;' . $crlf;
}

Expand Down

0 comments on commit c0d1c7a

Please sign in to comment.