que estoy tratando de hacer una función recursiva que construye un camino para una categoría específicafunciones recursivas almacenados en MySQL
CREATE FUNCTION getPath(inId INT)
RETURNS TEXT
DETERMINISTIC
BEGIN
DECLARE return_path TEXT;
DECLARE return_parent_id INT;
SELECT CONCAT('/', name) INTO return_path FROM article_categories WHERE id = inId;
SELECT parent_id INTO return_parent_id FROM article_categories WHERE id = inId;
IF return_parent_id > 0 THEN
SELECT CONCAT(getPath(return_parent_id), return_path) INTO return_path;
END IF;
RETURN return_path;
END
Cuando trato de ejecutar esta función con una categoría que no tiene padres (parent_id = 0) funciona bien, pero cuando pruebo una categoría que tiene un parent_id> 0 obtengo 1424 funciones almacenadas recursivas y los desencadenadores no están permitidos.
¿Cómo puedo solucionar esto? Voy a alojar este código en un servicio de alojamiento web normal que debe tener al menos la versión 5.1 del servidor MySQL.
Después de una cierta ayuda de Ike Walker he hecho un procedimineto en cambio, que funciona bien
DROP PROCEDURE IF EXISTS getPath;
DELIMITER //
CREATE PROCEDURE getPath(IN category_id INT UNSIGNED, OUT return_path TEXT)
BEGIN
DECLARE parent_id INT UNSIGNED;
DECLARE path_result TEXT;
SET max_sp_recursion_depth=50;
SELECT CONCAT('/', ac.name), ac.parent_id INTO return_path, parent_id FROM article_categories AS ac WHERE ac.id = category_id;
IF parent_id > 0 THEN
CALL getPath(parent_id, path_result);
SELECT CONCAT(path_result, return_path) INTO return_path;
END IF;
END //
DELIMITER ;
Luego utilizo algo como esto llamarlo
CALL getPath(72, @temp); SELECT @temp;
En este momento estoy desarrollando en Ubuntu con la versión del servidor MySQL: 5.1.41-3ubuntu12.6 (Ubuntu) – Tirithen
He encontrado http: // foros .mysql.com/read.php? 98,224107,224638 # msg-224638 que habla de SET max_sp_recursion_depth = N; donde N es el número de recurrencias para permitir. Pero sigo recibiendo 1424 funciones almacenadas recursivas y los disparadores no están permitidos. – Tirithen