HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/AppData/Local/Microsoft/OneDrive/26.168.0830.0006/WebAssets/sql/folder_ancestors.sql
-- @query folder_ancestors
-- @db localContent 32.0
-- @param target_local_id INT
WITH RECURSIVE ancestors AS (
    SELECT m.LocalID, m.Name, m.ParentFSID, m.FileSystemID, 0 AS depth
    FROM localContent.ItemMetadata m
    WHERE m.LocalID = ?target_local_id
      AND m.Tombstoned = 0
    UNION ALL
    SELECT parent.LocalID, parent.Name, parent.ParentFSID, parent.FileSystemID, a.depth + 1
    FROM localContent.ItemMetadata parent
    INNER JOIN ancestors a ON parent.FileSystemID = a.ParentFSID
    WHERE parent.IsRootFolder = 0
      AND parent.Tombstoned = 0
)
SELECT LocalID AS localId, Name AS name, lower(hex(FileSystemID)) AS fileSystemId
FROM ancestors
ORDER BY depth DESC