Recover original view, trigger, routine if creating fails (bug #3601088)
This commit is contained in:
parent
1e310977b6
commit
737c2bdc0e
|
@ -338,23 +338,64 @@ function grant($grant, $privileges, $columns, $on) {
|
|||
/** Drop old object and create a new one
|
||||
* @param string drop query
|
||||
* @param string create query
|
||||
* @param string rollback query
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
* @return bool dropped
|
||||
* @return null redirect in success
|
||||
*/
|
||||
function drop_create($drop, $create, $location, $message_drop, $message_alter, $message_create, $name) {
|
||||
function drop_create($drop, $create, $rollback, $location, $message_drop, $message_alter, $message_create, $name) {
|
||||
if ($_POST["drop"]) {
|
||||
return query_redirect($drop, $location, $message_drop, true, !$_POST["dropped"]);
|
||||
query_redirect($drop, $location, $message_drop);
|
||||
} else {
|
||||
if ($name != "") {
|
||||
queries($drop);
|
||||
}
|
||||
queries_redirect($location, ($name != "" ? $message_alter : $message_create), queries($create));
|
||||
if ($name != "") {
|
||||
queries($rollback);
|
||||
}
|
||||
}
|
||||
$dropped = $name != "" && ($_POST["dropped"] || queries($drop));
|
||||
$created = queries($create);
|
||||
if (!queries_redirect($location, ($name != "" ? $message_alter : $message_create), $created) && $dropped) {
|
||||
redirect(null, $message_drop);
|
||||
}
|
||||
|
||||
/** Generate SQL query for creating trigger
|
||||
* @param string
|
||||
* @return array result of trigger()
|
||||
*/
|
||||
function create_trigger($on, $row) {
|
||||
global $jush;
|
||||
$timing_event = " $row[Timing] $row[Event]";
|
||||
return "CREATE TRIGGER "
|
||||
. idf_escape($row["Trigger"])
|
||||
. ($jush == "mssql" ? $on . $timing_event : $timing_event . $on)
|
||||
. rtrim(" $row[Type]\n$row[Statement]", ";")
|
||||
. ";";
|
||||
}
|
||||
|
||||
/** Generate SQL query for creating routine
|
||||
* @param string "PROCEDURE" or "FUNCTION"
|
||||
* @param array result of routine()
|
||||
* @return string
|
||||
*/
|
||||
function create_routine($routine, $row) {
|
||||
global $inout;
|
||||
$set = array();
|
||||
$fields = (array) $row["fields"];
|
||||
ksort($fields); // enforce fields order
|
||||
foreach ($fields as $field) {
|
||||
if ($field["field"] != "") {
|
||||
$set[] = (ereg("^($inout)\$", $field["inout"]) ? "$field[inout] " : "") . idf_escape($field["field"]) . process_type($field, "CHARACTER SET");
|
||||
}
|
||||
}
|
||||
return $dropped;
|
||||
return "CREATE $routine "
|
||||
. idf_escape(trim($row["name"]))
|
||||
. " (" . implode(", ", $set) . ")"
|
||||
. (isset($_GET["function"]) ? " RETURNS" . process_type($row["returns"], "CHARACTER SET") : "")
|
||||
. ($row["language"] ? " LANGUAGE $row[language]" : "")
|
||||
. rtrim("\n$row[definition]", ";")
|
||||
. ";";
|
||||
}
|
||||
|
||||
/** Remove current user definer from SQL command
|
||||
|
|
|
@ -2,41 +2,31 @@
|
|||
$PROCEDURE = $_GET["procedure"];
|
||||
$routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE");
|
||||
$routine_languages = routine_languages();
|
||||
$row = ($PROCEDURE == "" ? array("fields" => array()) : routine($PROCEDURE, $routine));
|
||||
$row["name"] = $PROCEDURE;
|
||||
|
||||
$dropped = false;
|
||||
if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
|
||||
$set = array();
|
||||
$fields = (array) $_POST["fields"];
|
||||
ksort($fields); // enforce fields order
|
||||
foreach ($fields as $field) {
|
||||
if ($field["field"] != "") {
|
||||
$set[] = (ereg("^($inout)\$", $field["inout"]) ? "$field[inout] " : "") . idf_escape($field["field"]) . process_type($field, "CHARACTER SET");
|
||||
}
|
||||
if ($_POST) {
|
||||
if (!$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
|
||||
drop_create(
|
||||
"DROP $routine " . idf_escape($PROCEDURE),
|
||||
create_routine($routine, $_POST),
|
||||
create_routine($routine, $row),
|
||||
substr(ME, 0, -1),
|
||||
lang('Routine has been dropped.'),
|
||||
lang('Routine has been altered.'),
|
||||
lang('Routine has been created.'),
|
||||
$PROCEDURE
|
||||
);
|
||||
}
|
||||
$dropped = drop_create(
|
||||
"DROP $routine " . idf_escape($PROCEDURE),
|
||||
"CREATE $routine " . idf_escape(trim($_POST["name"])) . " (" . implode(", ", $set) . ")" . (isset($_GET["function"]) ? " RETURNS" . process_type($_POST["returns"], "CHARACTER SET") : "") . (in_array($_POST["language"], $routine_languages) ? " LANGUAGE $_POST[language]" : "") . rtrim("\n$_POST[definition]", ";") . ";",
|
||||
substr(ME, 0, -1),
|
||||
lang('Routine has been dropped.'),
|
||||
lang('Routine has been altered.'),
|
||||
lang('Routine has been created.'),
|
||||
$PROCEDURE
|
||||
);
|
||||
$row = $_POST;
|
||||
$row["fields"] = (array) $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);
|
||||
|
||||
$collations = get_vals("SHOW CHARACTER SET");
|
||||
sort($collations);
|
||||
$row = array("fields" => array());
|
||||
if ($_POST) {
|
||||
$row = $_POST;
|
||||
$row["fields"] = (array) $row["fields"];
|
||||
process_fields($row["fields"]);
|
||||
} elseif ($PROCEDURE != "") {
|
||||
$row = routine($PROCEDURE, $routine);
|
||||
$row["name"] = $PROCEDURE;
|
||||
}
|
||||
?>
|
||||
|
||||
<form action="" method="post" id="form">
|
||||
|
@ -55,6 +45,5 @@ if (isset($_GET["function"])) {
|
|||
<p>
|
||||
<input type="submit" value="<?php echo lang('Save'); ?>">
|
||||
<?php if ($PROCEDURE != "") { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"<?php echo confirm(); ?>><?php } ?>
|
||||
<?php if ($dropped) { ?><input type="hidden" name="dropped" value="1"><?php } ?>
|
||||
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
||||
</form>
|
||||
|
|
|
@ -2,28 +2,26 @@
|
|||
$TABLE = $_GET["trigger"];
|
||||
$trigger_options = trigger_options();
|
||||
$trigger_event = array("INSERT", "UPDATE", "DELETE");
|
||||
$row = (array) trigger($_GET["name"]) + array("Trigger" => $TABLE . "_bi");
|
||||
|
||||
$dropped = false;
|
||||
if ($_POST && !$error && in_array($_POST["Timing"], $trigger_options["Timing"]) && in_array($_POST["Event"], $trigger_event) && in_array($_POST["Type"], $trigger_options["Type"])) {
|
||||
$timing_event = " $_POST[Timing] $_POST[Event]";
|
||||
$on = " ON " . table($TABLE);
|
||||
$dropped = drop_create(
|
||||
"DROP TRIGGER " . idf_escape($_GET["name"]) . ($jush == "pgsql" ? $on : ""),
|
||||
"CREATE TRIGGER " . idf_escape($_POST["Trigger"]) . ($jush == "mssql" ? $on . $timing_event : $timing_event . $on) . rtrim(" $_POST[Type]\n$_POST[Statement]", ";") . ";",
|
||||
ME . "table=" . urlencode($TABLE),
|
||||
lang('Trigger has been dropped.'),
|
||||
lang('Trigger has been altered.'),
|
||||
lang('Trigger has been created.'),
|
||||
$_GET["name"]
|
||||
);
|
||||
if ($_POST) {
|
||||
if (!$error && in_array($_POST["Timing"], $trigger_options["Timing"]) && in_array($_POST["Event"], $trigger_event) && in_array($_POST["Type"], $trigger_options["Type"])) {
|
||||
$on = " ON " . table($TABLE);
|
||||
drop_create(
|
||||
"DROP TRIGGER " . idf_escape($_GET["name"]) . ($jush == "pgsql" ? $on : ""),
|
||||
create_trigger($on, $_POST),
|
||||
create_trigger($on, $row + array("Type" => reset($trigger_options["Type"]))),
|
||||
ME . "table=" . urlencode($TABLE),
|
||||
lang('Trigger has been dropped.'),
|
||||
lang('Trigger has been altered.'),
|
||||
lang('Trigger has been created.'),
|
||||
$_GET["name"]
|
||||
);
|
||||
}
|
||||
$row = $_POST;
|
||||
}
|
||||
|
||||
page_header(($_GET["name"] != "" ? lang('Alter trigger') . ": " . h($_GET["name"]) : lang('Create trigger')), $error, array("table" => $TABLE));
|
||||
|
||||
$row = $_POST;
|
||||
if (!$row) {
|
||||
$row = trigger($_GET["name"]) + array("Trigger" => $TABLE . "_bi");
|
||||
}
|
||||
?>
|
||||
|
||||
<form action="" method="post" id="form">
|
||||
|
@ -37,6 +35,5 @@ if (!$row) {
|
|||
<p>
|
||||
<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 ($dropped) { ?><input type="hidden" name="dropped" value="1"><?php } ?>
|
||||
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
||||
</form>
|
||||
|
|
|
@ -1,33 +1,32 @@
|
|||
<?php
|
||||
$TABLE = $_GET["view"];
|
||||
$dropped = false;
|
||||
if ($_POST && !$error) {
|
||||
$name = trim($_POST["name"]);
|
||||
$dropped = drop_create(
|
||||
"DROP VIEW " . table($TABLE),
|
||||
"CREATE VIEW " . table($name) . " AS\n$_POST[select]",
|
||||
($_POST["drop"] ? substr(ME, 0, -1) : ME . "table=" . urlencode($name)),
|
||||
lang('View has been dropped.'),
|
||||
lang('View has been altered.'),
|
||||
lang('View has been created.'),
|
||||
$TABLE
|
||||
);
|
||||
$row = ($TABLE == "" ? array() : view($TABLE));
|
||||
$row["name"] = $TABLE;
|
||||
|
||||
if ($_POST) {
|
||||
if (!$error) {
|
||||
$name = trim($_POST["name"]);
|
||||
drop_create(
|
||||
"DROP VIEW " . table($TABLE),
|
||||
"CREATE VIEW " . table($name) . " AS\n$_POST[select]",
|
||||
"CREATE VIEW " . table($TABLE) . " AS\n$row[select]",
|
||||
($_POST["drop"] ? substr(ME, 0, -1) : ME . "table=" . urlencode($name)),
|
||||
lang('View has been dropped.'),
|
||||
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);
|
||||
|
||||
$row = $_POST;
|
||||
if (!$row && $TABLE != "") {
|
||||
$row = view($TABLE);
|
||||
$row["name"] = $TABLE;
|
||||
}
|
||||
?>
|
||||
|
||||
<form action="" method="post">
|
||||
<p><?php echo lang('Name'); ?>: <input name="name" value="<?php echo h($row["name"]); ?>" maxlength="64" autocapitalize="off">
|
||||
<p><?php textarea("select", $row["select"]); ?>
|
||||
<p>
|
||||
<?php if ($dropped) { // old view was dropped but new wasn't created ?><input type="hidden" name="dropped" value="1"><?php } ?>
|
||||
<input type="submit" value="<?php echo lang('Save'); ?>">
|
||||
<?php if ($_GET["view"] != "") { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"<?php echo confirm(); ?>><?php } ?>
|
||||
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
Adminer 3.6.4-dev:
|
||||
Recover original view, trigger, routine if creating fails
|
||||
Disable autocapitalize in identifiers
|
||||
Indeterminate state of select all checkboxes
|
||||
|
||||
|
|
Loading…
Reference in a new issue