-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhyponyms_cycles.sql
executable file
·50 lines (42 loc) · 1.96 KB
/
hyponyms_cycles.sql
1
2
3
4
5
6
7
8
9
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
DROP PROCEDURE IF EXISTS hyponyms_cycles//
CREATE PROCEDURE hyponyms_cycles (
IN cur_title VARCHAR(255)) /** title of category which starts the cycle */
COMMENT 'Stores titles of categories (which form the cycle) to the table cat_cycles'
proc2:
BEGIN
DECLARE n_cycle TINYINT UNSIGNED;
DECLARE title, cc_titles VARCHAR(255);
DECLARE done, error BOOL DEFAULT FALSE;
/** SELECT '' AS '13 DEBUG hyponyms_cycles', cur_title AS 'cur_title';*/
SELECT n_depth FROM cat_parent_stack WHERE page_title=cur_title INTO n_cycle;
/** SELECT '' AS '15 DEBUG hyponyms_cycles', n_cycle AS 'n_cycle';*/
/** Debug message */
/** SELECT '' AS 'ERROR: The cycle of categories is found',
page_title,n_depth FROM cat_parent_stack WHERE n_depth >= n_cycle;*/
BEGIN
DECLARE cur
CURSOR FOR
SELECT page_title
FROM cat_parent_stack
WHERE n_depth >= n_cycle;
DECLARE
CONTINUE HANDLER FOR
SQLSTATE '02000'
SET done = TRUE;
OPEN cur;
IF error THEN SELECT 'ERROR OPEN CURSOR failed in PROCEDURE hyponyms_cycles'; LEAVE proc2; END IF;
SET cc_titles = '';
myLoop: LOOP
FETCH cur INTO title;
IF done THEN
CLOSE cur;
LEAVE myLoop;
END IF;
SET cc_titles = CONCAT(cc_titles, '|', title);
END LOOP;
IF CHAR_LENGTH(cc_titles) > 1 THEN
SET cc_titles = SUBSTRING(cc_titles,2); /** Trims first delimiter */
INSERT INTO cat_cycles (concat_titles) VALUES (cc_titles);
END IF;
END;
END; //