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ů.'),

View file

@ -1,6 +1,7 @@
Adminer 3.2.0-dev:
Get long texts and slow information by AJAX
All links and some forms by AJAX in browsers with support for history.pushState
Most links and forms by AJAX in browsers with support for history.pushState
Copy tables
Ability to search by expression in select
Export SQL command result (bug #3116854)
Focus first field with insert (bug #3126501)

View file

@ -1,17 +1,16 @@
Transactions in export
Create view and routine options
Variables editation, especially timezone (or set by PHP date.timezone)
Variables editation, especially timezone, or set by PHP date("0")
Highlight SQL textarea - may use external CodeMirror
Blob download and image display in edit form (important for Editor with hidden fields in select)
Add title to Logout, edit (in select) and select (in menu) in style "hever"
Blob download and image display in edit form (important for Editor with hidden fields in select and SQL command)
Add title to Logout, edit (in select) and select (in menu) for style "hever"
Shift-click in checkboxes to select range
Export by GET parameters
Only first part of big BZ2 export is readable, files are missing in TAR
Auto-refresh processlist (thanks to Jan Garaj)
Double click in select - Esc to abort editation
Draggable columns in alter table (thanks to Michal Manak)
? Filter by value in row under <thead> in select
? Column and table names auto-completition in SQL textarea
? Column and table names auto-completition in SQL textarea - http://blog.quplo.com/2010/06/css-code-completion-in-your-browser/
? Aliasing of built-in functions can save 7 KB, function minification can save 7 KB, substitution of repetitive $a["a"] can save 4 KB, substitution of $_GET and friends can save 2 KB, aliasing of $connection->query can save 24 B, JS Closure compiler can save 2 KB, not enclosing HTML attribute values can save 1.2 KB, replacing \\n by \n can save .3 KB
? Branch binary_compile: LZW compression of translations can save 30 KB, LZW compression of all texts can save 11 KB, remove of base64_decode() + using chars 127-255 in minification can save 1 KB
@ -29,6 +28,7 @@ Data longer than max_allowed_packet can be sent by mysqli_stmt_send_long_data()
? Geometry support
SQLite:
Copy tables
ASC and DESC instead of text length in index
Delimiter in export and SQL command
Backward keys in Editor