Driver specific trigger options
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1478 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
0fd28dcccb
commit
f9dd7aad69
|
@ -412,12 +412,14 @@ WHERE OBJECT_NAME(indexes.object_id) = " . $connection2->quote($table)
|
|||
$result = $connection->query("SELECT s.name [Trigger],
|
||||
CASE WHEN OBJECTPROPERTY(s.id, 'ExecIsInsertTrigger') = 1 THEN 'INSERT' WHEN OBJECTPROPERTY(s.id, 'ExecIsUpdateTrigger') = 1 THEN 'UPDATE' WHEN OBJECTPROPERTY(s.id, 'ExecIsDeleteTrigger') = 1 THEN 'DELETE' END [Event],
|
||||
CASE WHEN OBJECTPROPERTY(s.id, 'ExecIsInsteadOfTrigger') = 1 THEN 'INSTEAD OF' ELSE 'AFTER' END [Timing],
|
||||
c.text [Statement]
|
||||
c.text
|
||||
FROM sysobjects s
|
||||
JOIN syscomments c ON s.id = c.id
|
||||
WHERE s.xtype = 'TR' AND s.name = " . $connection->quote($name)
|
||||
);
|
||||
return $result->fetch_assoc();
|
||||
$row = $result->fetch_assoc();
|
||||
$row["Statement"] = preg_replace('~^.+\\s+AS\\s+~isU', '', $row["text"]); //! identifiers, comments
|
||||
return $row;
|
||||
}
|
||||
|
||||
function triggers($table) {
|
||||
|
@ -436,6 +438,13 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . $connection->quote($table)
|
|||
return $return;
|
||||
}
|
||||
|
||||
function trigger_options() {
|
||||
return array(
|
||||
"Timing" => array("AFTER", "INSTEAD OF"),
|
||||
"Type" => array("AS"),
|
||||
);
|
||||
}
|
||||
|
||||
function support($feature) {
|
||||
return ereg('^(view|routine|trigger)$', $feature);
|
||||
}
|
||||
|
|
|
@ -454,7 +454,7 @@ if (!defined("DRIVER")) {
|
|||
*/
|
||||
function view($name) {
|
||||
global $connection;
|
||||
return array("select" => preg_replace('~^(?:[^`]|`[^`]*`)* AS ~U', '', $connection->result("SHOW CREATE VIEW " . idf_escape($name), 1)));
|
||||
return array("select" => preg_replace('~^(?:[^`]|`[^`]*`)*\\s+AS\\s+~isU', '', $connection->result("SHOW CREATE VIEW " . idf_escape($name), 1)));
|
||||
}
|
||||
|
||||
/** Get sorted grouped list of collations
|
||||
|
@ -648,6 +648,14 @@ if (!defined("DRIVER")) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
function trigger_options() {
|
||||
return array(
|
||||
"Timing" => array("BEFORE", "AFTER"),
|
||||
// Event is always INSERT, UPDATE, DELETE
|
||||
"Type" => array("FOR EACH ROW"),
|
||||
);
|
||||
}
|
||||
|
||||
/** Explain select
|
||||
* @param Min_DB
|
||||
* @param string
|
||||
|
|
|
@ -397,7 +397,7 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu
|
|||
|
||||
function trigger($name) {
|
||||
global $connection;
|
||||
$result = $connection->query('SELECT trigger_name AS "Trigger", condition_timing AS "Timing", event_manipulation AS "Event", action_statement AS "Statement" FROM information_schema.triggers WHERE event_object_table = ' . $connection->quote($_GET["trigger"]) . ' AND trigger_name = ' . $connection->quote($name));
|
||||
$result = $connection->query('SELECT trigger_name AS "Trigger", condition_timing AS "Timing", event_manipulation AS "Event", action_statement AS "Statement" FROM information_schema.triggers WHERE event_object_table = ' . $connection->quote($_GET["trigger"]) . ' AND trigger_name = ' . $connection->quote($name)); //! detect Type
|
||||
return $result->fetch_assoc();
|
||||
}
|
||||
|
||||
|
@ -411,6 +411,13 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu
|
|||
return $return;
|
||||
}
|
||||
|
||||
function trigger_options() {
|
||||
return array(
|
||||
"Timing" => array("BEFORE", "AFTER"),
|
||||
"Type" => array("FOR EACH STATEMENT", "FOR EACH ROW"),
|
||||
);
|
||||
}
|
||||
|
||||
function explain($connection, $query) {
|
||||
return $connection->query("EXPLAIN $query");
|
||||
}
|
||||
|
|
|
@ -453,6 +453,13 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
function trigger_options() {
|
||||
return array(
|
||||
"Timing" => array("BEFORE", "AFTER", "INSTEAD OF"),
|
||||
"Type" => array("FOR EACH ROW"),
|
||||
);
|
||||
}
|
||||
|
||||
function explain($connection, $query) {
|
||||
return $connection->query("EXPLAIN $query");
|
||||
}
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
<?php
|
||||
$TABLE = $_GET["trigger"];
|
||||
$trigger_time = array("BEFORE", "AFTER");
|
||||
$trigger_options = trigger_options();
|
||||
$trigger_event = array("INSERT", "UPDATE", "DELETE");
|
||||
|
||||
$dropped = false;
|
||||
if ($_POST && !$error && in_array($_POST["Timing"], $trigger_time) && in_array($_POST["Event"], $trigger_event)) {
|
||||
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 " . idf_escape($TABLE);
|
||||
$dropped = drop_create(
|
||||
"DROP TRIGGER " . idf_escape($_GET["name"]) . ($driver == "pgsql" ? " ON " . idf_escape($TABLE) : ""),
|
||||
"CREATE TRIGGER " . idf_escape($_POST["Trigger"]) . " $_POST[Timing] $_POST[Event] ON " . idf_escape($TABLE) . " FOR EACH ROW\n$_POST[Statement]", //! FOR EACH STATEMENT
|
||||
"CREATE TRIGGER " . idf_escape($_POST["Trigger"]) . ($driver == "mssql" ? $on . $timing_event : $timing_event . $on) . " $_POST[Type]\n$_POST[Statement]",
|
||||
ME . "table=" . urlencode($TABLE),
|
||||
lang('Trigger has been dropped.'),
|
||||
lang('Trigger has been altered.'),
|
||||
|
@ -28,14 +30,15 @@ if ($_POST) {
|
|||
|
||||
<form action="" method="post" id="form">
|
||||
<table cellspacing="0">
|
||||
<tr><th><?php echo lang('Time'); ?><td><?php echo html_select("Timing", $trigger_time, $row["Timing"], "if (/^" . h(preg_quote($TABLE, "/")) . "_[ba][iud]$/.test(this.form['Trigger'].value)) this.form['Trigger'].value = '" . h(addcslashes($TABLE, "\r\n'\\")) . "_' + selectValue(this).charAt(0).toLowerCase() + selectValue(this.form['Event']).charAt(0).toLowerCase();"); ?>
|
||||
<tr><th><?php echo lang('Time'); ?><td><?php echo html_select("Timing", $trigger_options["Timing"], $row["Timing"], "if (/^" . h(preg_quote($TABLE, "/")) . "_[ba][iud]$/.test(this.form['Trigger'].value)) this.form['Trigger'].value = '" . h(addcslashes($TABLE, "\r\n'\\")) . "_' + selectValue(this).charAt(0).toLowerCase() + selectValue(this.form['Event']).charAt(0).toLowerCase();"); ?>
|
||||
<tr><th><?php echo lang('Event'); ?><td><?php echo html_select("Event", $trigger_event, $row["Event"], "this.form['Timing'].onchange();"); ?>
|
||||
<tr><th><?php echo lang('Name'); ?><td><input name="Trigger" value="<?php echo h($row["Trigger"]); ?>" maxlength="64">
|
||||
<tr><th><?php echo lang('Type'); ?><td><?php echo html_select("Type", $trigger_options["Type"], $row["Type"]); ?>
|
||||
</table>
|
||||
<p><textarea name="Statement" rows="10" cols="80" style="width: 98%;"><?php echo h($row["Statement"]); ?></textarea>
|
||||
<p>
|
||||
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
||||
<?php if ($dropped) { ?><input type="hidden" name="dropped" value="1"><?php } ?>
|
||||
<?php echo lang('Name'); ?>: <input name="Trigger" value="<?php echo h($row["Trigger"]); ?>" maxlength="64">
|
||||
<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 } ?>
|
||||
</form>
|
||||
|
|
Loading…
Reference in a new issue