]> git.joonet.de Git - adminer.git/commitdiff
Copy tables (bug #3158027)
authorJakub Vrana <jakub@vrana.cz>
Tue, 1 Feb 2011 13:12:22 +0000 (14:12 +0100)
committerJakub Vrana <jakub@vrana.cz>
Tue, 1 Feb 2011 13:12:22 +0000 (14:12 +0100)
adminer/db.inc.php
adminer/drivers/mysql.inc.php
adminer/lang/cs.inc.php
changes.txt
todo.txt

index 590ec5cdb981fa0b19fb4628b71c01370f7f0300..2c8948dd82ddcdd6d053a127a0c8c2dea0d687fe 100644 (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";
index 6b258491fd4b295353adb183a46a68f6cc39e5ab..a7edc44a9635c076058a9b47dc0a5877dfb99b0e 100644 (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) {
index b021cc8f69393106969ca4463d4272282ead4dbd..227073ed6628daa49c1c4f206a11b94ee81631b8 100644 (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ů.'),
index 02efeb9dda4bc4a1d423e427394a3e7b328c5b43..ecab7ccc59a28437095dc2b161ae124301269d58 100644 (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)
index d569ef0e2f2a0a8724b85111c30e94ce772e38fc..cbca945f7583c8f49d69734a7a09a57424968105 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -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