From 982974fe2752c0a724b4f2ca3f64aef086075248 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Mon, 13 May 2013 11:12:28 -0700 Subject: [PATCH] Use ALTER VIEW and don't use temporary object if changing name --- adminer/include/editing.inc.php | 24 +++++++++++++++++------- adminer/procedure.inc.php | 4 +++- adminer/view.inc.php | 33 +++++++++++++++++++++------------ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index 11698251..7e21d55b 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -330,10 +330,12 @@ function grant($grant, $privileges, $columns, $on) { } /** Drop old object and create a new one -* @param string drop query -* @param string create query -* @param string test query -* @param string drop test query +* @param string drop old object query +* @param string create new object query +* @param string drop new object query +* @param string create test object query +* @param string drop test object query +* @param string * @param string * @param string * @param string @@ -341,14 +343,22 @@ function grant($grant, $privileges, $columns, $on) { * @param string * @return null redirect in success */ -function drop_create($drop, $create, $test, $drop_test, $location, $message_drop, $message_alter, $message_create, $name) { +function drop_create($drop, $create, $drop_created, $test, $drop_test, $location, $message_drop, $message_alter, $message_create, $old_name, $new_name) { if ($_POST["drop"]) { query_redirect($drop, $location, $message_drop); + } elseif ($old_name == "") { + query_redirect($create, $location, $message_create); + } elseif ($old_name != $new_name) { + $created = queries($create); + queries_redirect($location, $message_alter, $created && queries($drop)); + if ($created) { + queries($drop_created); + } } else { queries_redirect( $location, - ($name != "" ? $message_alter : $message_create), - ($name == "" || (queries($test) && queries($drop_test) && queries($drop))) && queries($create) + $message_alter, + queries($test) && queries($drop_test) && queries($drop) && queries($create) ); } } diff --git a/adminer/procedure.inc.php b/adminer/procedure.inc.php index c3f56e30..b91a5f4e 100644 --- a/adminer/procedure.inc.php +++ b/adminer/procedure.inc.php @@ -9,13 +9,15 @@ if ($_POST && !process_fields($row["fields"]) && !$error) { drop_create( "DROP $routine " . idf_escape($PROCEDURE), create_routine($routine, $row), + "DROP $routine " . idf_escape($row["name"]), 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 + $PROCEDURE, + $row["name"] ); } diff --git a/adminer/view.inc.php b/adminer/view.inc.php index b7c4d48b..772d9d9a 100644 --- a/adminer/view.inc.php +++ b/adminer/view.inc.php @@ -4,19 +4,28 @@ $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 - ); + $location = ME . "table=" . urlencode($name); + $message = lang('View has been altered.'); + + if (!$_POST["drop"] && $TABLE == $name && $jush != "sqlite") { + query_redirect(($jush == "mssql" ? "ALTER" : "CREATE OR REPLACE") . " VIEW " . table($name) . $as, $location, $message); + } else { + $temp_name = $name . "_adminer_" . uniqid(); + drop_create( + "DROP VIEW " . table($TABLE), + "CREATE VIEW " . table($name) . $as, + "DROP VIEW " . table($name), + "CREATE VIEW " . table($temp_name) . $as, + "DROP VIEW " . table($temp_name), + ($_POST["drop"] ? substr(ME, 0, -1) : $location), + lang('View has been dropped.'), + $message, + lang('View has been created.'), + $TABLE, + $name + ); + } } page_header(($TABLE != "" ? lang('Alter view') : lang('Create view')), $error, array("table" => $TABLE), $TABLE);