PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $sql_text = "-- создаем таблицу учёта рабочего времени create table job ( person text not null, reported real not null check (reported >= 0.0) ); -- создаем таблицу с общим временем работы create table total ( person text unique not null, hours real ); -- создаем триггер для обновления таблицы `total` create trigger total_trigger before insert on job begin select case when not exists (select 1 from total where person = new.person) then raise(rollback, 'Unknown person ') end; insert into total values (new.person, new.reported) on conflict(person) do update set hours = hours + new.reported; end; create trigger another_trigger after update on job begin INSERT into job values ('Test', 1); END; insert into job values ('Олег', 1.5), ('Сергей', 0.5), ('Олег', 1.0); select * from total;"; $regex = "/--\s*создаем\s*триггер.*?\bCREATE\s+TRIGGER\s+(\w+)\s+((?:BEFORE|AFTER)\s+(?:INSERT|UPDATE|DELETE)\s+ON\s+\w+|INSTEAD\s+OF\s+INSERT\s+ON\s+\w+)\s+BEGIN\s+((?:[^;]*;?(?![\s\r\n]*\bend\b))+)\s*\bend\b/si"; preg_match_all($regex, $sql_text, $matches); if (!empty($matches[0])) { foreach ($matches[0] as $key => $match) { $trigger_name = $matches[1][$key]; $trigger_event = $matches[2][$key]; $trigger_body = $matches[3][$key]; echo "Trigger Name: " . $trigger_name . "\n"; echo "Trigger Event: " . $trigger_event . "\n"; echo "Trigger Body:\n" . $trigger_body . "\n"; echo "--------------------\n"; } } else { echo "No triggers found.\n"; } ?>
Show:  
Copy Clear