About Us
Products
Purchase
Downloads
Support
Forums
Contact Us
Site
 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
MrCheviot
Novice


Joined: 02 Dec 2007
Posts: 42

PostPosted: Sat Apr 05, 2008 9:58 pm   

#DBPUT - Can't auto add to end?
 
Having another issue w/ #DBPUT today..

If I create a blank database (db), the first available record will be 0db. So I can #DBPUT 0 @datarec.

If I want to add a second record, it's #DBPUT 1 @datarec, and so forth.

It seems that #DBPUT is incapable of adding a new record to the "end" of the database. This is problematic for script driven DB entry, as there's no reliable way to get the next available record number. Here are the would-be options:

1. %numrec works if you are using a view that shows all records *and* no records have been deleted. If I have 0db - 4db (%numrec=5), and delete 3db, the next available record is 5db, although %numrec will return 4.

2. You can add a record to 0db, and then delete it, so the next available record is 1db. Thereafter, if you #DBPUT 0 @datarec, it will add records to the end. This works the best as far as adding, but I don't want to be reliant upon a 'db_init' alias to create a bogus record and delete it if I don't have to.

3. Store the number of records in a separate variable somewhere and increment with each addition. This isn't good, because if ZMUD crashes or you exit without saving settings, the variable will be off - or there's a very high chance it will be off, as the DB always seems to save.

Thus far, it seems that #2 is the best option, although I can't believe there's no way to just have it add a new record to the end (view dependent or not). Am I missing something here?

-MrC
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Apr 05, 2008 10:15 pm   
 
Heard of the #NEW command? It's specifically designed to create new records. It's best that you don't build your DB to be dependant on rec numbers, though. Create an index field that you can look up and increment and then iterate through to ensure everything stays proper when you delete things, or even better just don't use numbers at all.
_________________
EDIT: I didn't like my old signature
Reply with quote
MrCheviot
Novice


Joined: 02 Dec 2007
Posts: 42

PostPosted: Sat Apr 05, 2008 10:44 pm   
 
Hahaha.. clearly, hadn't heard of #NEW. Guess I was missing something here, although not sure how I missed something so obvious.

Thanks.

-MrC
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