|
|
|
|
@ -54,7 +54,7 @@ BEGIN
|
|
|
|
|
WITH RECURSIVE cte as (
|
|
|
|
|
SELECT v.id AS set_id, v.handle_id,
|
|
|
|
|
v.id AS data_set_id,
|
|
|
|
|
JSON_ARRAY(v.id) AS parent_chain
|
|
|
|
|
CAST('' AS CHAR(4096)) AS parent_chain
|
|
|
|
|
FROM (SELECT s.*, h.id as handle_id
|
|
|
|
|
FROM (voip_sound_sets s, voip_sound_handles h)
|
|
|
|
|
) AS v
|
|
|
|
|
@ -77,18 +77,16 @@ BEGIN
|
|
|
|
|
UNION
|
|
|
|
|
SELECT v.id AS set_id, v.handle_id,
|
|
|
|
|
IF(f.use_parent = 0, v.id, cte.data_set_id) AS data_set_id,
|
|
|
|
|
JSON_ARRAY_INSERT(cte.parent_chain, "$[0]", v.id) AS parent_chain
|
|
|
|
|
CONCAT(v.parent_id, IF(cte.parent_chain, ':', ''), cte.parent_chain) as parent_chain
|
|
|
|
|
FROM (SELECT s.*, h.id as handle_id, h.name as handle_name
|
|
|
|
|
FROM (voip_sound_sets s, voip_sound_handles h)
|
|
|
|
|
) AS v
|
|
|
|
|
LEFT JOIN voip_sound_files f ON f.handle_id = v.handle_id AND f.set_id = v.id
|
|
|
|
|
JOIN cte ON cte.set_id = v.parent_id AND cte.handle_id = v.handle_id
|
|
|
|
|
)
|
|
|
|
|
SELECT set_id, handle_id, IF(data_set_id = set_id, NULL, data_set_id) as data_set_id,
|
|
|
|
|
REPLACE(REPLACE(REPLACE(
|
|
|
|
|
JSON_REMOVE(cte.parent_chain, "$[0]"),
|
|
|
|
|
"[", ""), "]", ""), ", ", ":"
|
|
|
|
|
) AS parent_chain
|
|
|
|
|
SELECT set_id, handle_id,
|
|
|
|
|
IF(data_set_id = set_id, NULL, data_set_id) as data_set_id,
|
|
|
|
|
parent_chain
|
|
|
|
|
FROM cte;
|
|
|
|
|
ELSE
|
|
|
|
|
IF u_handle_id IS NOT NULL THEN
|
|
|
|
|
@ -101,7 +99,7 @@ BEGIN
|
|
|
|
|
WITH RECURSIVE cte as (
|
|
|
|
|
SELECT v.id AS set_id, v.handle_id,
|
|
|
|
|
v.id AS data_set_id,
|
|
|
|
|
JSON_ARRAY(v.id) AS parent_chain
|
|
|
|
|
CAST('' AS CHAR(4096)) AS parent_chain
|
|
|
|
|
FROM (SELECT s.*, h.id as handle_id
|
|
|
|
|
FROM (voip_sound_sets s, voip_sound_handles h)
|
|
|
|
|
) AS v
|
|
|
|
|
@ -111,18 +109,16 @@ BEGIN
|
|
|
|
|
UNION
|
|
|
|
|
SELECT v.id AS set_id, v.handle_id,
|
|
|
|
|
IF(f.use_parent = 0, v.id, cte.data_set_id) AS data_set_id,
|
|
|
|
|
JSON_ARRAY_INSERT(cte.parent_chain, "$[0]", v.id) AS parent_chain
|
|
|
|
|
CONCAT(v.parent_id, IF(cte.parent_chain, ':', ''), cte.parent_chain) as parent_chain
|
|
|
|
|
FROM (SELECT s.*, h.id as handle_id, h.name as handle_name
|
|
|
|
|
FROM (voip_sound_sets s, voip_sound_handles h)
|
|
|
|
|
) AS v
|
|
|
|
|
LEFT JOIN voip_sound_files f ON f.handle_id = v.handle_id AND f.set_id = v.id
|
|
|
|
|
JOIN cte ON cte.set_id = v.parent_id AND cte.handle_id = v.handle_id
|
|
|
|
|
)
|
|
|
|
|
SELECT set_id, handle_id, IF(data_set_id = set_id, NULL, data_set_id) as data_set_id,
|
|
|
|
|
REPLACE(REPLACE(REPLACE(
|
|
|
|
|
JSON_REMOVE(cte.parent_chain, "$[0]"),
|
|
|
|
|
"[", ""), "]", ""), ", ", ":"
|
|
|
|
|
) AS parent_chain
|
|
|
|
|
SELECT set_id, handle_id,
|
|
|
|
|
IF(data_set_id = set_id, NULL, data_set_id) as data_set_id,
|
|
|
|
|
parent_chain
|
|
|
|
|
FROM cte;
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
|
|
|