Subject Re: Storing headings and paragraphs in a Firebird database
Author certfb
Thank you Andre, this is exactly what I was looking for!

> Processing the hierarchy within one document is very easy using a recursion.

Could I ask how you have implemented the recursion - i.e. in the client, using a CTE or with a stored procedure?

The reason for asking is that AFAIK the ordering in the result set (from a CTE at least) is not defined. Therefore you could end up with:

Heading 1
Heading 1.3
Paragraph 1.3.2
Paragraph 1.3.1
Paragraph 1.3.3
Heading 1.2

So my original idea was to use this kind of adjacency structure but with an "IDPredecessor" and/or "IDSuccessor" instead of an "IDParent" and a "Depth" field. But although this would be easy to access in a programming language such as 'C', in SQL I thought I would end up doing a fetch for every record to work out which is the next one.

> I usually use a TreeView component to display to the user.

Yes, I plan something similar or possibly Tree + Rich Text that is parsed for paragraph marks.

> I hope I did not misunderstand what your question was :-)
You understood it perfectly :)