1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-24 15:12:51 +02:00

SQLite: Support UPDATE OF triggers

This commit is contained in:
Jakub Vrana
2014-03-15 10:58:24 -07:00
parent fc668ea326
commit 46bb56cab9
10 changed files with 40 additions and 13 deletions

View File

@@ -567,6 +567,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)
function trigger_options() {
return array(
"Timing" => array("AFTER", "INSTEAD OF"),
"Event" => array("INSERT", "UPDATE", "DELETE"),
"Type" => array("AS"),
);
}

View File

@@ -755,7 +755,7 @@ if (!defined("DRIVER")) {
/** Get information about trigger
* @param string trigger name
* @return array array("Trigger" => , "Timing" => , "Event" => , "Type" => , "Statement" => )
* @return array array("Trigger" => , "Timing" => , "Event" => , "Of" => , "Type" => , "Statement" => )
*/
function trigger($name) {
if ($name == "") {
@@ -778,12 +778,12 @@ if (!defined("DRIVER")) {
}
/** Get trigger options
* @return array ("Timing" => array(), "Type" => array())
* @return array ("Timing" => array(), "Event" => array(), "Type" => array())
*/
function trigger_options() {
return array(
"Timing" => array("BEFORE", "AFTER"),
// Event is always INSERT, UPDATE, DELETE
"Event" => array("INSERT", "UPDATE", "DELETE"),
"Type" => array("FOR EACH ROW"),
);
}

View File

@@ -507,6 +507,7 @@ ORDER BY conkey, conname") as $row) {
function trigger_options() {
return array(
"Timing" => array("BEFORE", "AFTER"),
"Event" => array("INSERT", "UPDATE", "DELETE"),
"Type" => array("FOR EACH ROW", "FOR EACH STATEMENT"),
);
}

View File

@@ -634,18 +634,21 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
if ($name == "") {
return array("Statement" => "BEGIN\n\t;\nEND");
}
$idf = '(?:[^`"\\s]+|`[^`]*`|"[^"]*")+';
$trigger_options = trigger_options();
preg_match(
'~^CREATE\\s+TRIGGER\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*(BEFORE|AFTER|INSTEAD\\s+OF)\\s+([a-z]+)\\s+ON\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*(?:FOR\\s*EACH\\s*ROW\\s)?(.*)~is',
"~^CREATE\\s+TRIGGER\\s*$idf\\s*(" . implode("|", $trigger_options["Timing"]) . ")\\s+([a-z]+)(?:\\s+OF\\s+($idf))?\\s+ON\\s*$idf\\s*(?:FOR\\s+EACH\\s+ROW\\s)?(.*)~is",
$connection->result("SELECT sql FROM sqlite_master WHERE type = 'trigger' AND name = " . q($name)),
$match
);
return array("Timing" => strtoupper($match[1]), "Event" => strtoupper($match[2]), "Trigger" => $name, "Statement" => $match[3]);
return array("Timing" => strtoupper($match[1]), "Event" => strtoupper($match[2]), "Of" => $match[3], "Trigger" => $name, "Statement" => $match[4]);
}
function triggers($table) {
$return = array();
$trigger_options = trigger_options();
foreach (get_rows("SELECT * FROM sqlite_master WHERE type = 'trigger' AND tbl_name = " . q($table)) as $row) {
preg_match('~^CREATE\\s+TRIGGER\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*([a-z]+)\\s*([a-z]+)~i', $row["sql"], $match);
preg_match('~^CREATE\\s+TRIGGER\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*(' . implode("|", $trigger_options["Timing"]) . ')\\s*(.*)\\s+ON\\b~iU', $row["sql"], $match);
$return[$row["name"]] = array($match[1], $match[2]);
}
return $return;
@@ -654,6 +657,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
function trigger_options() {
return array(
"Timing" => array("BEFORE", "AFTER", "INSTEAD OF"),
"Event" => array("INSERT", "UPDATE", "UPDATE OF", "DELETE"),
"Type" => array("FOR EACH ROW"),
);
}