MySql function returns null everytime


MySql function returns null everytime



I have the following function: (The SQL query works perfectly)


CREATE FUNCTION get_participantes (pid INT)
RETURNS varchar(255)
DETERMINISTIC
BEGIN
DECLARE par varchar(255);
SET par = (SELECT GROUP_CONCAT(mail SEPARATOR ',') FROM users WHERE id IN ( SELECT user_id FROM meeting_participants WHERE meeting_id = pid));
RETURN par;
END



And I'm trying to get the return of that function in the following procedure:


CREATE PROCEDURE google_calendar
(p1 varchar(50),
p2 INT,
p3 varchar(50),
p4 varchar(50),
p5 varchar(50),
p6 varchar(50),
p7 varchar(50),
p8 varchar(50))
BEGIN
DECLARE parti VARCHAR(255);
SET @parti = get_participantes(p2);
SELECT COALESCE(@parti,"nullpart") INTO @par2;
SET @cmd = CONCAT('curl "http://*****:80**/meetings/api/" --data-urlencode "id=',p1,'" --data-urlencode "participants=',@par2,'" --data-urlencode "agenda=',p2,'" --data-urlencode "title=',p4,'" --data-urlencode "lugar=',p5,'" --data-urlencode "inicio=',p6,'" --data-urlencode "duracion=',p7,'" --data-urlencode "delete=',p8,'"');
SET @result = sys_eval(@cmd);
END



I use the COALESCE to check if the return of the function is null. The parameters p1 to p8 are fields that i'm getting from a table using an AFTER INSERT TRIGGER. The p2 parameter that goes in the function, is the NEW.id that i get from the trigger. Also i have a error log that prints the parameters that the curl gets, this is an example:



I get nullpart in participants everytime even thought i pass the same parameter (p2) into agenda and it shows me the id perfectly. Please help.



The function works when i call it from outside the procedure:


> SELECT get_participantes(539);$
+------------------------+
| get_participantes(539) |
+------------------------+
| ybejarano@2secure.org |
+------------------------+





What happens if you select @parti?
– Bleach
Jun 29 at 21:49






What do you get if you do SELECT get_participantes(525)?
– Barmar
Jun 29 at 21:52


SELECT get_participantes(525)





@Bleach I get null.
– Yesid Bejarano Camacho
Jun 29 at 21:57






@Barmar IT work and give the emails separated by comma.
– Yesid Bejarano Camacho
Jun 29 at 21:58





How about SET @par2 = COALESCE(@parti,"nullpart"); instead of SELECT?
– Barmar
Jun 29 at 22:03


SET @par2 = COALESCE(@parti,"nullpart");


SELECT









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV