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; 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 of insert on \w+)\s+begin\s+(.*?)\bend\b/s"; 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"; // Separator for multiple matches } } else { echo "No triggers found.\n"; }
Show:  
Copy Clear