lundi 29 juin 2015

How to repeat creating of row and its dependencies in SQLite

I have a following table that support hierarchies of nodes (simplified for make explanation shorter):

╔═════╦═════════════╦═══════════╗
║ id  ║    name     ║ parent id ║
╠═════╬═════════════╬═══════════╣
║ 101 ║ some_parent ║        55 ║
║ 200 ║ A           ║       101 ║
║ 201 ║ B           ║       101 ║
║ 202 ║ C           ║       101 ║
╚═════╩═════════════╩═══════════╝

There is one more table that stores values:

╔═════╦═══════════╦═══════╗
║ id  ║ timestamp ║ value ║
╠═════╬═══════════╬═══════╣
║ 200 ║ 1.1.2015  ║ 1     ║
║ 200 ║ 2.1.2015  ║ 1.5   ║
║ 201 ║ 1.1.2015  ║ 2     ║
║ 201 ║ 2.1.2015  ║ 2.5   ║
║ 202 ║ 1.1.2015  ║ 3     ║
║ 202 ║ 2.1.2015  ║ 3.1   ║
╚═════╩═══════════╩═══════╝

My task is to create a node D as a child of some_parent and to fill values table with a values calculated in base of corresponded A, B, C.

Another issue is that there could be several nodes like some_parent in the DB and I need to repeat all the actions for each of them.

I resolved this problem for MS-SQL by using T-SQL loops.

The question is how to perform this in SQLite which have no loop constructs as I know.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire