Allow overwriting tables when copying them

This commit is contained in:
Jakub Vrana 2019-05-14 09:56:29 +02:00
parent f00f7a0e19
commit deea21dd2d
5 changed files with 8 additions and 3 deletions

View file

@ -140,7 +140,7 @@ if ($adminer->homepage()) {
echo "<p>" . lang('Move to other database') . ": ";
echo ($databases ? html_select("target", $databases, $db) : '<input name="target" value="' . h($db) . '" autocapitalize="off">');
echo " <input type='submit' name='move' value='" . lang('Move') . "'>";
echo (support("copy") ? " <input type='submit' name='copy' value='" . lang('Copy') . "'>" : "");
echo (support("copy") ? " <input type='submit' name='copy' value='" . lang('Copy') . "'> " . checkbox("overwrite", 1, $_POST["overwrite"], lang('overwrite')) : "");
echo "\n";
}
echo "<input type='hidden' name='all' value=''>"; // used by trCheck()

View file

@ -810,7 +810,8 @@ if (!defined("DRIVER")) {
queries("SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'");
foreach ($tables as $table) {
$name = ($target == DB ? table("copy_$table") : idf_escape($target) . "." . table($table));
if (!queries("CREATE TABLE $name LIKE " . table($table))
if (($_POST["overwrite"] && !queries("\nDROP TABLE IF EXISTS $name"))
|| !queries("CREATE TABLE $name LIKE " . table($table))
|| !queries("INSERT INTO $name SELECT * FROM " . table($table))
) {
return false;
@ -825,7 +826,8 @@ if (!defined("DRIVER")) {
foreach ($views as $table) {
$name = ($target == DB ? table("copy_$table") : idf_escape($target) . "." . table($table));
$view = view($table);
if (!queries("CREATE VIEW $name AS $view[select]")) { //! USE to avoid db.table
if (($_POST["overwrite"] && !queries("DROP VIEW IF EXISTS $name"))
|| !queries("CREATE VIEW $name AS $view[select]")) { //! USE to avoid db.table
return false;
}
}

View file

@ -127,6 +127,7 @@ $translations = array(
'Tables have been moved.' => 'Tabulky byly přesunuty.',
'Copy' => 'Zkopírovat',
'Tables have been copied.' => 'Tabulky byly zkopírovány.',
'overwrite' => 'přepsat',
'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ů.'),

View file

@ -128,6 +128,7 @@ $translations = array(
'Tables have been moved.' => 'Xx.',
'Copy' => 'Xx',
'Tables have been copied.' => 'Xx.',
'overwrite' => 'xx',
'Routines' => 'Xx',
'Routine has been called, %d row(s) affected.' => array('Xx, %d.', 'Xx, %d.'),

View file

@ -1,6 +1,7 @@
Adminer 4.7.2-dev:
Do not attempt logging in without password (bug #676)
Stretch footer over the whole table width (bug #624)
Allow overwriting tables when copying them
MySQL: Fix creating users and changing password in MySQL 8 (bug #663)
Adminer 4.7.1 (released 2019-01-24):