Don't drop original view and routine before creating the new one

This commit is contained in:
Jakub Vrana 2013-05-08 07:55:08 -07:00
parent b7021c9c7f
commit e99463b295
5 changed files with 63 additions and 45 deletions

View file

@ -340,7 +340,8 @@ function grant($grant, $privileges, $columns, $on) {
/** Drop old object and create a new one /** Drop old object and create a new one
* @param string drop query * @param string drop query
* @param string create query * @param string create query
* @param string rollback query * @param string test query
* @param string drop test query
* @param string * @param string
* @param string * @param string
* @param string * @param string
@ -348,17 +349,15 @@ function grant($grant, $privileges, $columns, $on) {
* @param string * @param string
* @return null redirect in success * @return null redirect in success
*/ */
function drop_create($drop, $create, $rollback, $location, $message_drop, $message_alter, $message_create, $name) { function drop_create($drop, $create, $test, $drop_test, $location, $message_drop, $message_alter, $message_create, $name) {
if ($_POST["drop"]) { if ($_POST["drop"]) {
query_redirect($drop, $location, $message_drop); query_redirect($drop, $location, $message_drop);
} else { } else {
if ($name != "") { queries_redirect(
queries($drop); $location,
} ($name != "" ? $message_alter : $message_create),
queries_redirect($location, ($name != "" ? $message_alter : $message_create), queries($create)); ($name == "" || (queries($test) && queries($drop_test) && queries($drop))) && queries($create)
if ($name != "") { );
queries($rollback);
}
} }
} }

View file

@ -1,16 +1,17 @@
<?php <?php
$PROCEDURE = $_GET["procedure"]; $PROCEDURE = $_GET["procedure"];
$routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE"); $routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE");
$routine_languages = routine_languages(); $row = $_POST;
$row = ($PROCEDURE == "" ? array("fields" => array()) : routine($PROCEDURE, $routine)); $row["fields"] = (array) $row["fields"];
$row["name"] = $PROCEDURE;
if ($_POST) { if ($_POST) {
if (!$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) { if (!$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
$temp_name = "$row[name]_adminer_" . uniqid();
drop_create( drop_create(
"DROP $routine " . idf_escape($PROCEDURE), "DROP $routine " . idf_escape($PROCEDURE),
create_routine($routine, $_POST),
create_routine($routine, $row), create_routine($routine, $row),
create_routine($routine, array("name" => $temp_name) + $row),
"DROP $routine " . idf_escape($temp_name),
substr(ME, 0, -1), substr(ME, 0, -1),
lang('Routine has been dropped.'), lang('Routine has been dropped.'),
lang('Routine has been altered.'), lang('Routine has been altered.'),
@ -18,15 +19,19 @@ if ($_POST) {
$PROCEDURE $PROCEDURE
); );
} }
$row = $_POST;
$row["fields"] = (array) $row["fields"];
process_fields($row["fields"]); process_fields($row["fields"]);
} }
page_header(($PROCEDURE != "" ? (isset($_GET["function"]) ? lang('Alter function') : lang('Alter procedure')) . ": " . h($PROCEDURE) : (isset($_GET["function"]) ? lang('Create function') : lang('Create procedure'))), $error); page_header(($PROCEDURE != "" ? (isset($_GET["function"]) ? lang('Alter function') : lang('Alter procedure')) . ": " . h($PROCEDURE) : (isset($_GET["function"]) ? lang('Create function') : lang('Create procedure'))), $error);
if (!$_POST && $PROCEDURE != "") {
$row = routine($PROCEDURE, $routine);
$row["name"] = $PROCEDURE;
}
$collations = get_vals("SHOW CHARACTER SET"); $collations = get_vals("SHOW CHARACTER SET");
sort($collations); sort($collations);
$routine_languages = routine_languages();
?> ?>
<form action="" method="post" id="form"> <form action="" method="post" id="form">

View file

@ -1,27 +1,36 @@
<?php <?php
$TABLE = $_GET["trigger"]; $TABLE = $_GET["trigger"];
$name = $_GET["name"];
$trigger_options = trigger_options(); $trigger_options = trigger_options();
$trigger_event = array("INSERT", "UPDATE", "DELETE"); $trigger_event = array("INSERT", "UPDATE", "DELETE");
$row = (array) trigger($_GET["name"]) + array("Trigger" => $TABLE . "_bi"); $row = (array) trigger($name) + array("Trigger" => $TABLE . "_bi");
if ($_POST) { if ($_POST) {
if (!$error && in_array($_POST["Timing"], $trigger_options["Timing"]) && in_array($_POST["Event"], $trigger_event) && in_array($_POST["Type"], $trigger_options["Type"])) { if (!$error && in_array($_POST["Timing"], $trigger_options["Timing"]) && in_array($_POST["Event"], $trigger_event) && in_array($_POST["Type"], $trigger_options["Type"])) {
// don't use drop_create() because there may not be more triggers for the same action
$on = " ON " . table($TABLE); $on = " ON " . table($TABLE);
drop_create( $drop = "DROP TRIGGER " . idf_escape($name) . ($jush == "pgsql" ? $on : "");
"DROP TRIGGER " . idf_escape($_GET["name"]) . ($jush == "pgsql" ? $on : ""), $location = ME . "table=" . urlencode($TABLE);
create_trigger($on, $_POST), if ($_POST["drop"]) {
create_trigger($on, $row + array("Type" => reset($trigger_options["Type"]))), query_redirect($drop, $location, lang('Trigger has been dropped.'));
ME . "table=" . urlencode($TABLE), } else {
lang('Trigger has been dropped.'), if ($name != "") {
lang('Trigger has been altered.'), queries($drop);
lang('Trigger has been created.'), }
$_GET["name"] queries_redirect(
); $location,
($name != "" ? lang('Trigger has been altered.') : lang('Trigger has been created.')),
queries(create_trigger($on, $_POST))
);
if ($name != "") {
queries(create_trigger($on, $row + array("Type" => reset($trigger_options["Type"]))));
}
}
} }
$row = $_POST; $row = $_POST;
} }
page_header(($_GET["name"] != "" ? lang('Alter trigger') . ": " . h($_GET["name"]) : lang('Create trigger')), $error, array("table" => $TABLE)); page_header(($name != "" ? lang('Alter trigger') . ": " . h($name) : lang('Create trigger')), $error, array("table" => $TABLE));
?> ?>
<form action="" method="post" id="form"> <form action="" method="post" id="form">
@ -34,6 +43,6 @@ page_header(($_GET["name"] != "" ? lang('Alter trigger') . ": " . h($_GET["name"
<p><?php textarea("Statement", $row["Statement"]); ?> <p><?php textarea("Statement", $row["Statement"]); ?>
<p> <p>
<input type="submit" value="<?php echo lang('Save'); ?>"> <input type="submit" value="<?php echo lang('Save'); ?>">
<?php if ($_GET["name"] != "") { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"<?php echo confirm(); ?>><?php } ?> <?php if ($name != "") { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"<?php echo confirm(); ?>><?php } ?>
<input type="hidden" name="token" value="<?php echo $token; ?>"> <input type="hidden" name="token" value="<?php echo $token; ?>">
</form> </form>

View file

@ -1,26 +1,30 @@
<?php <?php
$TABLE = $_GET["view"]; $TABLE = $_GET["view"];
$row = ($TABLE == "" ? array() : view($TABLE)); $row = $_POST;
$row["name"] = $TABLE;
if ($_POST) { if ($_POST && !$error) {
if (!$error) { $name = trim($row["name"]);
$name = trim($_POST["name"]); $temp_name = $name . "_adminer_" . uniqid();
drop_create( $as = " AS\n$row[select]";
"DROP VIEW " . table($TABLE), drop_create(
"CREATE VIEW " . table($name) . " AS\n$_POST[select]", "DROP VIEW " . table($TABLE),
"CREATE VIEW " . table($TABLE) . " AS\n$row[select]", "CREATE VIEW " . table($name) . $as,
($_POST["drop"] ? substr(ME, 0, -1) : ME . "table=" . urlencode($name)), "CREATE VIEW " . table($temp_name) . $as,
lang('View has been dropped.'), "DROP VIEW " . table($temp_name),
lang('View has been altered.'), ($_POST["drop"] ? substr(ME, 0, -1) : ME . "table=" . urlencode($name)),
lang('View has been created.'), lang('View has been dropped.'),
$TABLE lang('View has been altered.'),
); lang('View has been created.'),
} $TABLE
$row = $_POST; );
} }
page_header(($TABLE != "" ? lang('Alter view') : lang('Create view')), $error, array("table" => $TABLE), $TABLE); page_header(($TABLE != "" ? lang('Alter view') : lang('Create view')), $error, array("table" => $TABLE), $TABLE);
if (!$_POST && $TABLE != "") {
$row = view($TABLE);
$row["name"] = $TABLE;
}
?> ?>
<form action="" method="post"> <form action="" method="post">

View file

@ -1,6 +1,7 @@
Adminer 3.7.0-dev: Adminer 3.7.0-dev:
Allow more SQL files to be uploaded at the same time Allow more SQL files to be uploaded at the same time
Print run time next to executed queries Print run time next to executed queries
Don't drop original view and routine before creating the new one
Highlight default submit button Highlight default submit button
Disable SQL export when applying functions in select Disable SQL export when applying functions in select
Allow using lang() in plugins (customization) Allow using lang() in plugins (customization)