function for remove all foreign key constraints

This commit is contained in:
Thilina Buddika 2012-07-24 00:40:32 +05:30
parent db13811b31
commit ef43e97eca
2 changed files with 25 additions and 15 deletions

View File

@ -103,21 +103,7 @@ if (strlen($db) && (! empty($db_rename) || ! empty($db_copy))) {
'single_table' => isset($single_table)
)
);
foreach ($tables_full as $each_table => $tmp) {
$sql_constraints = '';
$sql_drop_foreign_keys = '';
$sql_structure = $export_sql_plugin->getTableDef(
$db, $each_table, "\n", '', false, false
);
if ($move && ! empty($sql_drop_foreign_keys)) {
PMA_DBI_query($sql_drop_foreign_keys);
}
// keep the constraint we just dropped
if (! empty($sql_constraints)) {
$GLOBALS['sql_constraints_query_full_db'][] = $sql_constraints;
}
}
unset($sql_constraints, $sql_drop_foreign_keys, $sql_structure);
PMA_removeAllForeignKeyConstraints($tables_full, $export_sql_plugin, $move);
foreach ($tables_full as $each_table => $tmp) {
// to be able to rename a db containing views,

View File

@ -337,4 +337,28 @@ function PMA_getSqlQueryAndCreateDbBeforeCopy()
return $sql_query;
}
/**
* remove all foreign key constraints
*
* @param array $tables_full array of all tables in given db or dbs
* @param instance $export_sql_plugin export plugin instance
* @param boolean $move whether databse name is empty or not
*/
function PMA_removeAllForeignKeyConstraints($tables_full, $export_sql_plugin, $move)
{
foreach ($tables_full as $each_table => $tmp) {
$sql_constraints = '';
$sql_drop_foreign_keys = '';
$sql_structure = $export_sql_plugin->getTableDef(
$GLOBALS['db'], $each_table, "\n", '', false, false
);
if ($move && ! empty($sql_drop_foreign_keys)) {
PMA_DBI_query($sql_drop_foreign_keys);
}
// keep the constraint we just dropped
if (! empty($sql_constraints)) {
$GLOBALS['sql_constraints_query_full_db'][] = $sql_constraints;
}
}
}
?>