- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
DELIMITER $$
DROP PROCEDURE IF EXISTS get_breadcrumbs$$
CREATE PROCEDURE get_breadcrumbs(IN current_id BIGINT(20), show_home TINYINT(1))
READS SQL DATA
BEGIN
DECLARE buff_id BIGINT(20);
DECLARE buff_parent_id BIGINT(20);
DECLARE done_search TINYINT(1);
DECLARE current_depth BIGINT(20);
SET done_search = 0;
SET current_depth = 0;
SET buff_id = NULL;
CREATE TEMPORARY TABLE breadcrumbs (id BIGINT(20), depth BIGINT(20)) ENGINE = MEMORY;
findloop : WHILE done_search = 0 DO
SELECT id, parent_id INTO buff_id, buff_parent_id FROM documents WHERE id = current_id;
IF buff_id IS NULL THEN
IF show_home != 0 THEN
SELECT id, parent_id INTO buff_id, buff_parent_id FROM documents WHERE alias = '/';
IF buff_id IS NOT NULL THEN
INSERT INTO breadcrumbs (id, depth) VALUES(buff_id, current_depth);
END IF;
END IF;
LEAVE findloop;
END IF;
INSERT INTO breadcrumbs (id, depth) VALUES(buff_id, current_depth);
SET current_id = buff_parent_id;
SET current_depth = current_depth + 1;
SET buff_id = NULL;
END WHILE findloop;
SELECT
d.id,
d.parent_id,
d.name,
d.alias,
b.depth
FROM breadcrumbs b
INNER JOIN documents d ON d.id = b.id
ORDER BY b.depth DESC;
END$$
DELIMITER ;
Хлебные крошки по id, parent_id.. Психанул...
DBdev 21.05.2013 14:56 # 0
А такое же, но через WITH не сделать?
deep 22.05.2013 01:21 # 0
Посему вот такая говнокожа..
deep 22.05.2013 01:23 # 0
DBdev 22.05.2013 12:21 # 0
> Неуж то решение не полохо?
А что там в мускуле есть альтернативного?
deep 23.05.2013 09:35 # +2