后插入触发器不起作用MySql

时间:2018-07-06 18:38:25

标签: mysql database triggers insert

我有这张桌子:

CREATE TABLE `meeting` ( `id` int(11) UNSIGNED NOT NULL,
                         `description` text COLLATE utf8_unicode_ci, 
                         `enddatetime` datetime DEFAULT NULL, 
                         `processedforlatestactivity` tinyint(1) UNSIGNED DEFAULT NULL, 
                         `location` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL, 
                         `logged` tinyint(1) UNSIGNED DEFAULT NULL,
                         `name` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL, 
                         `startdatetime` datetime DEFAULT NULL, 
                         `activity_id` int(11) UNSIGNED DEFAULT NULL, 
                         `category_customfield_id` int(11) UNSIGNED DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

另外一个用于保存用户和会议之间的关系:

CREATE TABLE `_user_meeting` ( `id` int(11) UNSIGNED NOT NULL, 
                               `meeting_id` int(11) UNSIGNED DEFAULT NULL,
                               `_user_id` int(11) UNSIGNED DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

最后我有这个触发器:

CREATE TRIGGER insert_meetingzurmo AFTER INSERT ON _user_meeting
     FOR EACH ROW BEGIN
      DECLARE id_concat varchar(50);
      DECLARE id_solo INT;
      SET id_solo = (SELECT max(id) FROM meeting);
      SET @id_solo = id_solo;
      SET id_concat = CONCAT('2scrm',@id_solo);
      SET @pid = id_concat;
      SET @ptitulo = (SELECT name FROM meeting WHERE meeting.id = @id_solo);
      SET @plocation = (SELECT location FROM meeting WHERE meeting.id = @id_solo);
      SET @ptime = (SELECT startdatetime FROM meeting WHERE meeting.id = @id_solo);
      SET @pendtime = (SELECT enddatetime FROM meeting WHERE meeting.id = @id_solo);
      SET @pduracion = TIME_TO_SEC(timediff(@pendtime, @ptime));

      CALL google_calendar(@pid,@ptitulo,@plocation,@ptime,@pduracion,"false");

      END

问题是当我创建触发器并尝试从我的网页创建会议时,该网页崩溃并显示一条错误消息。但是我去查看数据库并创建了会议,但是_user_meeting中没有插入内容。我不知道为什么,如果在_user_meeting中插入后执行触发器。没有触发器,效果会很好。

0 个答案:

没有答案