Browse files

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

  • Loading branch information...
1 parent b7021c9 commit e99463b295bbc683d2f809ead01b5103eb9f2093 @vrana committed May 8, 2013
Showing with 63 additions and 45 deletions.
  1. +8 −9 adminer/include/editing.inc.php
  2. +11 −6 adminer/procedure.inc.php
  3. +22 −13 adminer/trigger.inc.php
  4. +21 −17 adminer/view.inc.php
  5. +1 −0 changes.txt
View
17 adminer/include/editing.inc.php
@@ -340,25 +340,24 @@ 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 test query
+* @param string drop test query
* @param string
* @param string
* @param string
* @param string
* @param string
* @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"]) {
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);
- }
+ queries_redirect(
+ $location,
+ ($name != "" ? $message_alter : $message_create),
+ ($name == "" || (queries($test) && queries($drop_test) && queries($drop))) && queries($create)
+ );
}
}
View
17 adminer/procedure.inc.php
@@ -1,32 +1,37 @@
<?php
$PROCEDURE = $_GET["procedure"];
$routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE");
-$routine_languages = routine_languages();
-$row = ($PROCEDURE == "" ? array("fields" => array()) : routine($PROCEDURE, $routine));
-$row["name"] = $PROCEDURE;
+$row = $_POST;
+$row["fields"] = (array) $row["fields"];
if ($_POST) {
if (!$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
+ $temp_name = "$row[name]_adminer_" . uniqid();
drop_create(
"DROP $routine " . idf_escape($PROCEDURE),
- create_routine($routine, $_POST),
create_routine($routine, $row),
+ create_routine($routine, array("name" => $temp_name) + $row),
+ "DROP $routine " . idf_escape($temp_name),
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);
+if (!$_POST && $PROCEDURE != "") {
+ $row = routine($PROCEDURE, $routine);
+ $row["name"] = $PROCEDURE;
+}
+
$collations = get_vals("SHOW CHARACTER SET");
sort($collations);
+$routine_languages = routine_languages();
?>
<form action="" method="post" id="form">
View
35 adminer/trigger.inc.php
@@ -1,27 +1,36 @@
<?php
$TABLE = $_GET["trigger"];
+$name = $_GET["name"];
$trigger_options = trigger_options();
$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 (!$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);
- 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"]
- );
+ $drop = "DROP TRIGGER " . idf_escape($name) . ($jush == "pgsql" ? $on : "");
+ $location = ME . "table=" . urlencode($TABLE);
+ if ($_POST["drop"]) {
+ query_redirect($drop, $location, lang('Trigger has been dropped.'));
+ } else {
+ if ($name != "") {
+ queries($drop);
+ }
+ 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;
}
-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">
@@ -34,6 +43,6 @@
<p><?php textarea("Statement", $row["Statement"]); ?>
<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 ($name != "") { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"<?php echo confirm(); ?>><?php } ?>
<input type="hidden" name="token" value="<?php echo $token; ?>">
</form>
View
38 adminer/view.inc.php
@@ -1,26 +1,30 @@
<?php
$TABLE = $_GET["view"];
-$row = ($TABLE == "" ? array() : view($TABLE));
-$row["name"] = $TABLE;
+$row = $_POST;
-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;
+if ($_POST && !$error) {
+ $name = trim($row["name"]);
+ $temp_name = $name . "_adminer_" . uniqid();
+ $as = " AS\n$row[select]";
+ drop_create(
+ "DROP VIEW " . table($TABLE),
+ "CREATE VIEW " . table($name) . $as,
+ "CREATE VIEW " . table($temp_name) . $as,
+ "DROP VIEW " . table($temp_name),
+ ($_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
+ );
}
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">
View
1 changes.txt
@@ -1,6 +1,7 @@
Adminer 3.7.0-dev:
Allow more SQL files to be uploaded at the same time
Print run time next to executed queries
+Don't drop original view and routine before creating the new one
Highlight default submit button
Disable SQL export when applying functions in select
Allow using lang() in plugins (customization)

0 comments on commit e99463b

Please sign in to comment.