lundi 17 août 2015

Sqlite hierarchical query top down

I'm saving directories in simple sqlite table, like

dir_id dir_name dir_parent

And I want to query this table in the most efficient way, so what when I pull this data out I could fill up the tree in C++ in one traversal, that is, enter the trees from the top down so that on no insertion I wouldn't have parent that wasn't already inserted. For instance, this is some data:

dir_id dir_name dir_parent
1      root     -1
2      usr      1
3      bin      1
4      include  2

And so on. How do I perform such query in sqlite?

Aucun commentaire:

Enregistrer un commentaire