Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
14
Erster Beitrag:
vor 5 Monaten
Letzter Beitrag:
vor 4 Monaten, 3 Wochen
Beteiligte Autoren:
Sivaprakash, DarrenF, Fabrice Harari, Yogi Yang, Allard, Ruben Sanchez Peña, Paulo Oliveira, Al, Frans

[WD22] Deleting all child [dependent] records in a multi-tenant file

Startbeitrag von Sivaprakash am 16.02.2018 08: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

Antworten:

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/?2011008

von Paulo Oliveira - am 16.02.2018 13:44
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

von Sivaprakash - am 17.02.2018 11:34
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

von Al - am 17.02.2018 18:42
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

von Sivaprakash - am 20.02.2018 06:49
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.

von Frans - am 20.02.2018 07:56
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

von Ruben Sanchez Peña - am 20.02.2018 11:25
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

von Sivaprakash - am 20.02.2018 13:01
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

von Allard - am 20.02.2018 13:59
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?27161,44188

von DarrenF - am 20.02.2018 15:56
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

von Fabrice Harari - am 20.02.2018 18: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

von Sivaprakash - am 21.02.2018 05:08
Quote
Sivaprakash
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

I think you can write a recursive function that will keep on call itself as long as it finds a child for selected record.

This way you will reach at the end of recursion. Once there start deleting the records from down to up.

von Yogi Yang - am 22.02.2018 06:37
Yes Yogi Yang, that's what I'm planning to do. I'll try that out and let u know.

Happiness Always
BKR Sivaprakash

von Sivaprakash - am 22.02.2018 06:44
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.