From d74159b68f115e6deaf6487752e54fa3ff7e873f Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Sat, 29 Aug 2009 13:51:32 +0000 Subject: [PATCH] Print ALTER command instead of running it in export git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1042 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- adminer/dump.inc.php | 16 ++++++++-------- adminer/include/export.inc.php | 9 +++------ changes.txt | 1 + todo.txt | 1 - 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/adminer/dump.inc.php b/adminer/dump.inc.php index c6baa49b..5a55f985 100644 --- a/adminer/dump.inc.php +++ b/adminer/dump.inc.php @@ -46,7 +46,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; dump(($style == "CREATE+ALTER" ? preg_replace('~^CREATE DATABASE ~', '\\0IF NOT EXISTS ', $create) : $create) . ";\n"); } if ($style && $_POST["format"] == "sql") { - dump("USE " . idf_escape($db) . ";\n\n"); + dump(($style == "CREATE+ALTER" ? "SET @adminer_alter = '';\n" : "") . "USE " . idf_escape($db) . ";\n\n"); $out = ""; if ($dbh->server_info >= 5) { foreach (array("FUNCTION", "PROCEDURE") as $routine) { @@ -108,7 +108,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; // drop old tables $query = "SELECT TABLE_NAME, ENGINE, TABLE_COLLATION, TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE()"; dump("DELIMITER ;; -CREATE PROCEDURE adminer_drop () BEGIN +CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN DECLARE _table_name, _engine, _table_collation varchar(64); DECLARE _table_comment varchar(64); DECLARE done bool DEFAULT 0; @@ -130,20 +130,20 @@ while ($row = $result->fetch_assoc()) { } dump(" ELSE - SET @alter_table = CONCAT('DROP TABLE `', REPLACE(_table_name, '`', '``'), '`'); - PREPARE alter_command FROM @alter_table; - EXECUTE alter_command; -- returns can't return a result set in the given context with MySQL extension - DROP PREPARE alter_command; + SET alter_command = CONCAT(alter_command, 'DROP TABLE `', REPLACE(_table_name, '`', '``'), '`;\\n'); END CASE; END IF; UNTIL done END REPEAT; CLOSE tables; END;; DELIMITER ; -CALL adminer_drop; -DROP PROCEDURE adminer_drop; +CALL adminer_alter(@adminer_alter); +DROP PROCEDURE adminer_alter; "); } + if (in_array("CREATE+ALTER", array($style, $_POST["table_style"])) && $_POST["format"] == "sql") { + dump("SELECT @adminer_alter;\n"); + } } } dump(); diff --git a/adminer/include/export.inc.php b/adminer/include/export.inc.php index d3462ff7..a1515c97 100644 --- a/adminer/include/export.inc.php +++ b/adminer/include/export.inc.php @@ -19,7 +19,7 @@ function dump_table($table, $style, $is_view = false) { // create procedure which iterates over original columns and adds new and removes old $query = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLLATION_NAME, COLUMN_TYPE, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = " . $dbh->quote($table) . " ORDER BY ORDINAL_POSITION"; dump("DELIMITER ;; -CREATE PROCEDURE adminer_alter () BEGIN +CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN DECLARE _column_name, _collation_name, _column_type, after varchar(64) DEFAULT ''; DECLARE _column_default longtext; DECLARE _is_nullable char(3); @@ -76,14 +76,11 @@ CREATE PROCEDURE adminer_alter () BEGIN UNTIL done END REPEAT; CLOSE columns; IF @alter_table != '' OR add_columns != '' THEN - SET @alter_table = CONCAT('ALTER TABLE " . idf_escape($table) . "', SUBSTR(CONCAT(add_columns, @alter_table), 2)); - PREPARE alter_command FROM @alter_table; - EXECUTE alter_command; - DROP PREPARE alter_command; + SET alter_command = CONCAT(alter_command, 'ALTER TABLE " . idf_escape($table) . "', SUBSTR(CONCAT(add_columns, @alter_table), 2), ';\\n'); END IF; END;; DELIMITER ; -CALL adminer_alter; +CALL adminer_alter(@adminer_alter); DROP PROCEDURE adminer_alter; "); diff --git a/changes.txt b/changes.txt index dc9e70bc..f11c7257 100644 --- a/changes.txt +++ b/changes.txt @@ -4,6 +4,7 @@ Execute SQL file stored on server disk Compress export and import Display column comments in table overview Respect max_allowed_packet in CSV import +Print ALTER command instead of running it in export Click on row selects it Fix Editor date format Fix long SQL query crash (bug #2839231) diff --git a/todo.txt b/todo.txt index cb58b620..bb34fea7 100644 --- a/todo.txt +++ b/todo.txt @@ -1,5 +1,4 @@ Bulk database drop -Print CREATE+ALTER export instead of running it Add whisperer to fields with foreign key Highlight found fields MySQL 5 BIT data type