Trying to get this function installed but can't get it correct.
delimiter //
--DROP FUNCTION IF EXISTS add_category_lang;
CREATE FUNCTION add_category_lang (parent INT, name VARCHAR(128)) RETURNS INT
DETERMINISTIC
MODIFIES SQL DATA
BEGIN
DECLARE idlang INT DEFAULT 1;
DECLARE nameval VARCHAR(128);
DECLARE done INT DEFAULT 0;
SELECT stripIllegalChars(name) INTO nameval;
DECLARE cur_lang CURSOR FOR SELECT id_lang FROM ps_lang;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur_lang;
REPEAT
FETCH cur_lang INTO idlang;
IF NOT done THEN
INSERT INTO ps_category_lang(id_category, id_lang, name, link_rewrite)
VALUES (parent, idlang, nameval, link_rewrite);
END IF; -- IF NOT done
UNTIL done END REPEAT;
CLOSE cur_lang;
RETURN 0;
END//
delimiter ;
I get a 1064 at DECLARE cur_lang CURSOR line. I think it may have something to do with the previous line:
SELECT stripIllegalChars(name) INTO nameval;
It looks correct and the function does exist. Can anyone see any obvious problems here that I'm overlooking?
The function is to place a record in ps_category_lang for each language in ps_lang.