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
This commit is contained in:
jakubvrana 2009-08-29 13:51:32 +00:00
parent 0a2d81d75a
commit d74159b68f
4 changed files with 12 additions and 15 deletions

View file

@ -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();

View file

@ -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;
");

View file

@ -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)

View file

@ -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