我创建了 2 个完美运行的函数:
DROP FUNCTION IF EXISTS get_participantes;
CREATE FUNCTION get_participantes ()
RETURNS varchar(255)
DETERMINISTIC
BEGIN
DECLARE par varchar(255);
DECLARE id_solo INT;
SET id_solo = (SELECT max(id) FROM meetings);
SET @id_solo = id_solo;
SET group_concat_max_len = 2048;
SET par = (SELECT GROUP_CONCAT(mail SEPARATOR ',') FROM users WHERE id IN ( SELECT user_id FROM meeting_participants WHERE meeting_id = @id_solo));
RETURN par;
END
DROP FUNCTION IF EXISTS get_agenda;
CREATE FUNCTION get_agenda()
RETURNS TEXT
DETERMINISTIC
BEGIN
DECLARE age TEXT;
DECLARE id_solo2 INT;
SET id_solo2 = (SELECT max(id) FROM meetings);
SET @id_solo2 = id_solo2;
SET group_concat_max_len = 2048;
SET age = (SELECT GROUP_CONCAT(text SEPARATOR 'n') from meeting_contents WHERE meeting_id = @id_solo2);
RETURN age;
END
我正在尝试在以下过程中调用此函数:
DROP PROCEDURE IF EXISTS google_calendar;
CREATE PROCEDURE google_calendar
(idConcat varchar(50),
pTitulo varchar(50),
pLugar varchar(50),
pInicio varchar(50),
pDuracion varchar(50),
pDelete varchar(50))
BEGIN
SELECT get_participantes() INTO @participante_comma;
SELECT get_agenda() INTO @agenda_texto;
SELECT IF(@participante_comma IS NULL, 'empty', @participante_comma) INTO @par_final;
SELECT IF(@agenda_texto IS NULL, 'empty', @agenda_texto) INTO @agenda_final;
SET @cmd = CONCAT('curl "http://***.**.**:8**/meetings/api/" --data-urlencode "id=',idConcat,'" --data-urlencode "participants=',@par_final,'" --data-urlencode "agenda=',@agenda_final,'" --data-urlencode "title=',pTitulo,'" --data-urlencode "lugar=',pLugar,'" --data-urlencode "inicio=',pInicio,'" --data-urlencode "duracion=',pDuracion,'" --data-urlencode "delete=',pDelete,'"');
SET @result = sys_eval(@cmd);
END
但是由于某种原因,当我通过首先调用过程来执行函数时,变量@participante_comma
,@agenda_texto
每次都返回 null。但是,如果我从 MySql 控制台使用 SELECT 执行函数,它会返回我想要的。
> SELECT get_participantes();$
+---------------------------------------------+
| get_participantes() |
+---------------------------------------------+
| czambrano@2secure.org,ybejarano@2secure.org |
+---------------------------------------------+
我不明白为什么在存储过程中不起作用。请帮忙。
没关系。我刚刚意识到问题:触发器不是异步的,在会议中插入某些内容后,meetings_participants中插入了内容。但是当我执行我的函数时,还没有插入meeting_participants。我将触发器从"在会议中插入后"更改为"在meeting_participants上插入后",仅此而已。