As I can't change anything in this DB, I had to implement everything in Pascal. Yeah, I don't like this solution, as it puts more stress on DB, as it requires much more queries and isn't atomic, as I have to store some data in temporary objects, that can possible lose sync with DB, while I read some other data. (But I'm not sure about it. May be Transaction object can make it atomic.) But I have no choice.