PDA

View Full Version : Help me locate and delete nodes...



zuilin
November 5th, 2020, 23:30
I'm iterating through database entries that I've created trying to delete them and I must be doing something wrong. Here is my code and the database:


for k, v in pairs(ztWindowRecordList.getChildren()) do
if (DB.getValue(v, "windowNodePath") == sWindowNodePath) and (DB.getValue(v, "windowClass") == cWindowClass) then
DB.deleteChild(v, k);
end
end


and


<DM_ZTabber>
<ztabber_window_list>
<id-00001>
<windowClass type="string">masterindex</windowClass>
<windowNodePath type="string">tables</windowNodePath>
</id-00001>
<id-00002>
<windowClass type="string">table</windowClass>
<windowNodePath type="string">tables.id-00001</windowNodePath>
</id-00002>
</ztabber_window_list>
</DM_ZTabber>



The database looks exactly how I want it. What I want to do is now delete, say, the entry with id-0002 if the data in "windowClass" and "windowNodePath" match some variable information in my script (sWindowNodePath and cWindowClass).

I'm pretty sure I'm doing something wrong because the data never gets deleted from the DB.

Thanks.

damned
November 6th, 2020, 00:01
make sure you hit /save after doing it - fg runs from an in memory DB and writes to disk every 5 mins
is the code right? i dont know :)

zuilin
November 6th, 2020, 00:02
make sure you hit /save after doing it - fg runs from an in memory DB and writes to disk every 5 mins
is the code right? i dont know :)

I have been.

Does the code look right?

zuilin
November 6th, 2020, 00:17
Duh.

I was doing it wrong.

Here's the corrected code for future reference:



for k, v in pairs(ztWindowRecordList.getChildren()) do
if (DB.getValue(v, "windowNodePath") == sWindowNodePath) and (DB.getValue(v, "windowClass") == cWindowClass) then
DB.deleteChild(ztWindowRecordList, k);
end
end