Skip to content

Commit

Permalink
Use ALTER VIEW and don't use temporary object if changing name
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed May 13, 2013
1 parent 3ed0ce9 commit 982974f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
24 changes: 17 additions & 7 deletions adminer/include/editing.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,25 +330,35 @@ 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
* @param string
* @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)
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion adminer/procedure.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
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"]
);
}

Expand Down
33 changes: 21 additions & 12 deletions adminer/view.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@

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);
Expand Down

0 comments on commit 982974f

Please sign in to comment.