Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Talahaski
Enchanter


Joined: 10 Oct 2000
Posts: 656
Location: USA

PostPosted: Sat Dec 06, 2003 10:55 pm   

#delkey
 
Can somebody help me with the syntax for #delkey or %delkey. I cannot quite figure out what is the "rec" and what is the "key".

I have a database created from the database interface called Container, or Co.

I have columns of Object as text, Count as number.

I currently have 10 records in the database, I want to create a trigger to clear out all records in the database.

I tried %delkey(&Num,"2co") to see if it deletes record 2, but it does not.

I also tried %delkey(&object,"test") to see if it deleted the record having a value of test in the object column, no luck here either.

#delkey co %rec does not work either.


It says the syntax is #delkey database-record key or %delkey(rec,key).

But in my situation, what is the database-record,rec, or key?
Reply with quote
Toetag
Magician


Joined: 10 Oct 2000
Posts: 356
Location: USA

PostPosted: Sun Dec 07, 2003 4:28 am   
 
Would the #DBDELETE command work more along the lines of what you are looking for? I don't use the DB commands too often so i'm shooting from the hip.

or I could be reading this DB stuff all backwards and be completely off the mark....
Reply with quote
Talahaski
Enchanter


Joined: 10 Oct 2000
Posts: 656
Location: USA

PostPosted: Sun Dec 07, 2003 5:11 am   
 
that's what I needed, thanks. I must have missed that command.


Using this I should be able to delete all records.

#DBFIRST
#WHILE (!%null( %rec)) {#sh ##dbdelete &Num;#DBNEXT}
Reply with quote
Talahaski
Enchanter


Joined: 10 Oct 2000
Posts: 656
Location: USA

PostPosted: Fri Dec 12, 2003 5:10 am   
 
Any idea why this code only delete about half the records instead of everything?

#DBFIRST
#WHILE (!%null( %rec)) {#sh ##dbdelete &Num;#DBNEXT}
Reply with quote
Talahaski
Enchanter


Joined: 10 Oct 2000
Posts: 656
Location: USA

PostPosted: Fri Dec 12, 2003 5:33 am   
 
For more information I populate the database using

#FORALL @Container/Contents {
#var testnnn "%i"
#NEW cobycount object=@testnnn}
#VIEW cobycount
#DBFIRST
#WHILE (!%null( %rec)) {
#SHOW %format( "&5.0f &s &s", &count, " ", &object)
#DBNEXT}

This creates 6 records.

after some other processing these records are left out there, so I want to delete them for next time I use the script.

but using this code seems to only delete half the records at a time.
#DBFIRST
#WHILE (!%null( %rec)) {#sh ##dbdelete &Num;#DBNEXT}


Running it the first time leaves 3 records, running it a second time leaves 1 record, running it the third time deletes them all.

Variable @Contents has the following data.
2 gold royales|3 copper farthings|4 silver moons|a gold ignoble|3 silver shillings|4 copper pennies
Reply with quote
Talahaski
Enchanter


Joined: 10 Oct 2000
Posts: 656
Location: USA

PostPosted: Fri Dec 12, 2003 5:36 am   
 
AHHHHHHHHHHHHH

I got it.


#DBFIRST
#WHILE (!%null( %rec)) {#dbdelete &Num}

seems the delete goes to the next, so having a DBNEXT resuylts in skipping
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Dec 12, 2003 5:42 am   
 
I can't say for sure, but it's probably caused by deleting the records.
You start at the first record in the view. You delete that record. Now that it's deleted, that record is no longer in the view so the first (and current) record would probably move to the original second record. After that, you do a #DBNEXT which would advance the current record to the original third record before doing the second #SHOW and #DBDELETE, thereby skipping the original second record. This will continue throughout the database so that you end up only deleting half the records. (this is all guesswork)

Seems like #LOOPVIEW would probably be a simpler choice for the loop. You should probably make a list of the records to delete first, then do the deletions with a #FORALL loop.
#VA dbdel {}
#LOOPV All {#SH ##ADDK dbdel &num}
#FO @dbdel {#DBD %i}
#UNV dbdel

EDIT: I see you reached the same conclusion yourself while I was writing this.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net