PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → [WD22] Deleting all child [dependent] records in a multi-tenant file
[WD22] Deleting all child [dependent] records in a multi-tenant file
Débuté par Sivaprakash, 16 fév. 2018 09:10 - 12 réponses
Posté le 16 février 2018 - 09:10
Hello,

[WD22] [ using postgres now, should work with any database ] [ multi - tenant ]

I need to delete a set of records which is having dependent child records also in the same file. Say

TenantInd Code Name ParentCode
100 101 Name - 1 Null
100 102 Child - 11 101
100 103 Child - 111 102
100 104 Child - 1111 103
....

I need to delete records pertaining to TenantID = 100 only. Since this records are having FK integrity, it need to be deleted from the last child to first parent [ bottom up approach ? ].

Is there any simple way of deleting those records in Windev, that I need not go through writing cursors or something similar ?

Happiness Always
BKR Sivaprakash
Posté le 16 février 2018 - 14:44
If you use HF and the referential integrity is defined in the Analysis to delete the record in the member file just delete the record in the owner file.

If you don't have it in the Analysis the fastest option is to use one delete query for each file and run it when needed.


https://doc.windev.com/en-US/…
Posté le 17 février 2018 - 12:34
Paulo Oliveria,

I need to delete a set of records which is having dependent child records also in the same file.

In the above file, I can't delete record with Code: 101 till record with Code: 102 is deleted. And record with Code : 102 can't be deleted till Code: 103 is deleted. Now I need to way to find the last record (Code : 104), delete it. Then go up (Code: 103) and delete that record.

Any ways ?

Happiness Always
BKR Sivaprakash
Posté le 17 février 2018 - 19:42
Hello Sivaprakash

You could set a filter on the child files on the parent key and then HreadLast and use HreadPrevious to work backwards through the data.

Regards
Al
Posté le 20 février 2018 - 07:49
Thanks AI.

Your logic will work only if only one level of child is there. Say if Code 103 got its own child, say 107, deleting 103 is possible only if 107 is deleted. And 107 may also have a child (or children).... this goes on.

Need to find a way to find the record which got no children, start deleting from that record.

Happiness Always
BKR Sivaprakash
Posté le 20 février 2018 - 08:56
Hello Sivaprakash,

If I understand it right:

Browse the master file. Make a query on the second file and if HnbRec(subFile)=0 then you can delete the record in the masterfile.
Posté le 20 février 2018 - 12:25
Hi.

I have seen that the ParentCode field can have Null values, so I think you can do it in two steps:

1) Assign the Null value to the ParentCode field of the records that are to be deleted.
2) Delete the record.

Rubén
Posté le 20 février 2018 - 14:01
Ruben,

Yes ParentCode fields could be null. That's for records that have no parents. But those records can have child(ren), and that child can have child(ren). This goes without any limit. Few records can go a depth of 5 levels, few could stop with 3 levels.

Need to find a way to start from the last record that's got no children and go up.

Happiness Always
BKR Sivaprakash
Posté le 20 février 2018 - 14:59
Hi

I would go by just foillowing the path what needs to be done.

Find the last recoord. ( hreadseekfirst(......)
Find it delete it find the one obove that an go on and on

regards
Allard
Posté le 20 février 2018 - 16:56
Hi,

A while ago, Carlo Hermus posted this on the WinDev Solutions section of this forum. I found it very useful for traversing my product (parent/child) category structure.

Just a thought; you might also find it useful?

http://27130.foren.mysnip.de/read.php…
Posté le 20 février 2018 - 19:08
Hi

this is how I manage this kind of problem:
I put the first record ID in an array
I start a loop on the array
for each line of the array, I find the dependents (a simple query suffice for that) and add them at the end of the aray
Exit the loop when I find no dependent and I'm on the last line of the array
end

At the end of this simple process, I have the list of all dependents, and I just need to loop on the array, starting from the end, and delete each record (in your case)

Best regards
Posté le 21 février 2018 - 06:08
Thanks Darren Farmer. This is what exactly I've. Need to study Treeview concept to change it to delete records.

Thanks Fabrice Harari. It's the logic I do in my powerbuilder application. Searching for better solutions, if any, in Windev.

Happiness Always
BKR Sivaprakash
Posté le 22 février 2018 - 07:44
Yes Yogi Yang, that's what I'm planning to do. I'll try that out and let u know.

Happiness Always
BKR Sivaprakash