adriano.freitas
Active Member
Helo! I'm developing a project that uses a recursive query. It happens that when testing the SQL sentence in several tools, it works ok, however, when inserting in my application made in B4A the application closes. I was able to identify that the problem occurs in the execution of the query, which leads me to believe that it is a question of the SQLite version that might not support recursion as I did. Could someone help me see in the query what could be wrong and, if applicable, help change it so that it works? Thank you all.
My Query:
with recursive itens (nivel, codigo, pai , estrutura,
ordem, titulo, status, tipo , temfilhos) as (
select 0 as nivel, codigo, pai, estrutura,
ordem, titulo, status, substr(conteudo || ' ',1,1) tipo,
(CASE WHEN ((SELECT Count(*) FROM arvore arvore2
WHERE pai=arvore.codigo)=0)
THEN 'N'
ELSE 'S'
END) as temfilhos
from arvore
where pai = 0
union all
select itens.nivel + 1, arvore.codigo, arvore.pai ,
arvore.estrutura, arvore.ordem, arvore.titulo,
arvore.status, substr(arvore.conteudo || ' ',1,1) tipo,
(CASE WHEN ((SELECT Count(*) FROM arvore arvore2
WHERE pai=arvore.codigo)=0)
THEN 'N'
ELSE 'S'
END) as temfilhos
from itens
join arvore on itens.codigo = Arvore.pai
order by itens.nivel+1 desc, arvore.ordem )
select nivel, codigo, pai , estrutura,
ordem, titulo, status, tipo , temfilhos
from itens;