depage-xmldb v2.3.1
XML documents in a relational database
Loading...
Searching...
No Matches
TreeSql.php
Go to the documentation of this file.
1<?php
2
12
13namespace Depage\XmlDb\Helpers;
14
26{
43 public static function descendants(string $table, string $anchorCondition, int $pad): string
44 {
45 return "WITH RECURSIVE tree (root_id, id, id_parent, lvl, sortkey) AS
46 (
47 SELECT x.id, x.id, x.id_parent, 0, CAST('' AS CHAR(5000))
48 FROM {$table} AS x
49 WHERE {$anchorCondition}
50 UNION ALL
51 SELECT tree.root_id, x.id, x.id_parent, tree.lvl + 1, CONCAT(tree.sortkey, LPAD(IFNULL(x.pos + 1, 0), {$pad}, '0'))
52 FROM {$table} AS x INNER JOIN tree
53 ON x.id_parent = tree.id
54 )";
55 }
56}
57
58/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
static descendants(string $table, string $anchorCondition, int $pad)
builds the recursive common table expression selecting a node matched by $anchor and all of its desce...
Definition TreeSql.php:43