1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-15 19:13:59 +02:00

Copy tables (bug #3158027)

This commit is contained in:
Jakub Vrana
2011-02-01 14:12:22 +01:00
parent c5b594d067
commit 741b19bc79
5 changed files with 46 additions and 9 deletions

View File

@@ -4,7 +4,7 @@ $tables_views = array_merge((array) $_POST["tables"], (array) $_POST["views"]);
if ($tables_views && !$error && !$_POST["search"]) {
$result = true;
$message = "";
if ($jush == "sql" && count($_POST["tables"]) > 1 && ($_POST["drop"] || $_POST["truncate"])) {
if ($jush == "sql" && count($_POST["tables"]) > 1 && ($_POST["drop"] || $_POST["truncate"] || $_POST["copy"])) {
queries("SET foreign_key_checks = 0"); // allows to truncate or drop several tables at once
}
if ($_POST["truncate"]) {
@@ -15,6 +15,9 @@ if ($tables_views && !$error && !$_POST["search"]) {
} elseif ($_POST["move"]) {
$result = move_tables((array) $_POST["tables"], (array) $_POST["views"], $_POST["target"]);
$message = lang('Tables have been moved.');
} elseif ($_POST["copy"]) {
$result = copy_tables((array) $_POST["tables"], (array) $_POST["views"], $_POST["target"]);
$message = lang('Tables have been copied.');
} elseif ($_POST["drop"]) {
if ($_POST["views"]) {
$result = drop_views($_POST["views"]);
@@ -76,7 +79,9 @@ if ($adminer->homepage()) {
$db = (isset($_POST["target"]) ? $_POST["target"] : (support("scheme") ? $_GET["ns"] : DB));
echo "<p>" . lang('Move to other database') . ": ";
echo ($databases ? html_select("target", $databases, $db) : '<input name="target" value="' . h($db) . '">');
echo " <input type='submit' name='move' value='" . lang('Move') . "' onclick='eventStop(event);'>\n";
echo " <input type='submit' name='move' value='" . lang('Move') . "' onclick='eventStop(event);'>";
echo (support("copy") ? " <input type='submit' name='copy' value='" . lang('Copy') . "'>" : "");
echo "\n";
}
}
echo "</form>\n";

View File

@@ -646,6 +646,7 @@ if (!defined("DRIVER")) {
/** Move tables to other schema
* @param array
* @param array
* @param string
* @return bool
*/
@@ -658,6 +659,34 @@ if (!defined("DRIVER")) {
//! move triggers
}
/** Copy tables to other schema
* @param array
* @param array
* @param string
* @return bool
*/
function copy_tables($tables, $views, $target) {
foreach ($tables as $table) {
$name = ($target == DB ? table("copy_$table") : idf_escape($target) . "." . table($table));
if (!queries("DROP TABLE IF EXISTS $name")
|| !queries("CREATE TABLE $name LIKE " . table($table))
|| !queries("INSERT INTO $name SELECT * FROM " . table($table))
) {
return false;
}
}
foreach ($views as $table) {
$name = ($target == DB ? table("copy_$table") : idf_escape($target) . "." . table($table));
$view = view($table);
if (!queries("DROP VIEW IF EXISTS $name")
|| !queries("CREATE VIEW $name AS $view[select]") //! USE to avoid db.table
) {
return false;
}
}
return true;
}
/** Get information about trigger
* @param string trigger name
* @return array array("Trigger" => , "Timing" => , "Event" => , "Statement" => )
@@ -865,7 +894,7 @@ if (!defined("DRIVER")) {
}
/** Check whether a feature is supported
* @param string "comment", "drop_col", "dump", "event", "partitioning", "routine", "scheme", "sequence", "status", "trigger", "type", "variables", "view"
* @param string "comment", "drop_col", "dump", "event", "partitioning", "routine", "scheme", "sequence", "status", "trigger", "type", "variables", "view", "copy"
* @return bool
*/
function support($feature) {

View File

@@ -105,6 +105,8 @@ $translations = array(
'Move to other database' => 'Přesunout do jiné databáze',
'Move' => 'Přesunout',
'Tables have been moved.' => 'Tabulky byly přesunuty.',
'Copy' => 'Zkopírovat',
'Tables have been copied.' => 'Tabulky byly zkopírovány.',
'Routines' => 'Procedury a funkce',
'Routine has been called, %d row(s) affected.' => array('Procedura byla zavolána, byl změněn %d záznam.', 'Procedura byla zavolána, byly změněny %d záznamy.', 'Procedura byla zavolána, bylo změněno %d záznamů.'),