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
Kalma
Newbie


Joined: 16 Mar 2004
Posts: 7
Location: USA

PostPosted: Tue Mar 16, 2004 5:43 pm   

Database querying
 
Hi :)

Summary:
Is there another way of #view/#find/#query (or their % counterparts) that just returns the row number (not the record number) of something from a view?

Background:
I've created a database that is essentially a top X donater's list. When they donate I search the database and see if they've already donated, if they have I add the new donation to the old donation, if not then I add them new. This works mostly fine. (Have had odd, unreproducable/inconsistant issues where PersonA's name gets changed to PersonB's, but it's not as troublesome as the other issue I'm having.)

Ok, so that was search #1

Then in the same trigger I search through it *again* to find their position in the list and report it back to them. This works fine too.

That's search #2

I use the #while loop found in zmud's help files to cycle through the database. My problem is that when I had 10 people in the list it was very fast and very smooth. However now that there are 66+ people in the list, it's getting very slow and I can only guess how slow it will become as more people get added.

I understand it's the slowest/worst way possible to utilize a database. But I have to do both searches so when I report their position back it's the most current, and the first one is obvious why I need it.

thanks very much, i'm sure it's just something i'm overlooking or not understanding correctly.

k
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Tue Mar 16, 2004 9:34 pm   
 
Well, actually, I don't understand why you need the row number instead of the record number. All other database functions and command let you give them the recor dnumber to access the record directly, so there is no need to loop through the view.
Reply with quote
Kalma
Newbie


Joined: 16 Mar 2004
Posts: 7
Location: USA

PostPosted: Tue Mar 16, 2004 10:54 pm   
 
Because the records aren't entered in the order I want. I could probably use the record number to update or create a new entry, but I'd still have to search through the view once to find their row number (Rank).

A simple version would be this:

Row Rec Name Amount
1 10ti A 1000
2 5ti C 500
3 15ti B 250

Player A tithes me, he's the top player but the 10th person entered in the database. I could use the query to update his information, but would still have to search the database to make sure his position didn't change on last update.

If there were an easy way to renumber the database so it's in the order I want it, that would work too. :)
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Mar 17, 2004 1:30 am   
 
You could use the %query function to find the 'Rank'. After you update the record thier rank would be %numitems(%query(&Amount>=%rec.Amount)). Ties will value all equally, but it is certainely faster.
Reply with quote
Kalma
Newbie


Joined: 16 Mar 2004
Posts: 7
Location: USA

PostPosted: Wed Mar 17, 2004 6:47 am   
 
That worked perfectly. I probably cut all the code in half and while I haven't run it in the game yet, all tests appear to work quickly and correctly.

Thank you so much for all your help!
k
Reply with quote
Kalma
Newbie


Joined: 16 Mar 2004
Posts: 7
Location: USA

PostPosted: Fri Apr 09, 2004 4:58 pm   
 
Hi :)
I've had about a month to test it and probably 90% of the time it works great, however I'm running into a very odd problem.

When it does a search for the person's name sometimes it won't find it, assumes it's a new name, and creates a duplicate. Then the next time it goes in, since there are two, the variable gets set wrong and it and makes another new entry, and so on. This happens relatively randomly and is annoying but easy to manually fix so I'm not as worried about it.

The other thing it does is work fine for a few days and then decide to reset all the information in the record everytime I try to add to it. (It doesn't announce itself as a new name, it finds the record, just deletes all the old info and puts new info)

Now, the weird bit. It seems to be very random when it decides to break. The first time I ran it, it worked relatively fine for about 2 weeks and then whenever certain people would trigger it, they'd always get the 2nd error (where it just deletes all their prior information) I figured the numbers were just too big (180 people, 11m in the 'total' list), so I reset the entire database to 0 and started over. That time it lasted about a week before 2 people started getting that error (60 people/records, 2m in the totals and remember only 2 people are 'broken' everyone else works). I reset it again to 0. Now the database has been working for 2 days and I've already got a person that gets reset to 0 whenever he tithes me (33 people 400k).

Keep in mind that this works great 90% of the time, even when it's not working for one or two people, it still works fine for everyone else that triggers it. When it breaks I haven't been able to find a pattern to it. I have records from all three databases if you'd like them and here is the bit of code where it searches and adds:

#var dbtesting 0 'initialize
#var dbtesting %find( @myname) 'search for record
#echo @dbtesting 'echos the record #
#if {!@dbtesting} { 'No record found - New Name
#echo It's a NEW Name!
#NEW argh {Name=@myname|Count=1|Total=@mytithe} 'straight add to db
#var dbtempcount 1 'setting vars for
#var dbtemptotal @mytithe 'the placement list
#var dbtesting %find( @myname) 'getting record #
} {
#var dbcurrec %left( @dbtesting, %len( @dbtesting)-2) 'strip off the letters from rec #
#var dorkedcount @dbcurrec".Count" 'manipulations to make it
#var dorkedcount2 "@"@dorkedcount 'read the records/varibles
#var dorkedtotal @dbcurrec".Total" 'correctly.
#var dorkedtotal2 "@"@dorkedtotal 'same
#math dbtempcount @dorkedcount2+1 'same
#math dbtemptotal @dorkedtotal2+@mytithe 'same
#dBPUT @dbtesting {Count=@dbtempcount|Total=@dbtemptotal} 'adding to the database
}


If you can give me any ideas why it's bugging that would be wonderful. I don't know if it's a limitation in the database itself, bad programming on my part or whatever. The comments that I put in aren't in the code, I just added them so you'd know what I was doing.

Thanks again for your help.
k
Reply with quote
Pega
Magician


Joined: 08 Jan 2001
Posts: 341
Location: Singapore

PostPosted: Fri Apr 09, 2004 7:08 pm   
 
I notice that too, for certain intervals of time (split second) the %find() function cannot find anything and i miss out whole portions of database matches.

I am still sorting out a good way around it. Perhaps the #priority command during each database query might help.
Reply with quote
Kalma
Newbie


Joined: 16 Mar 2004
Posts: 7
Location: USA

PostPosted: Fri Apr 09, 2004 7:44 pm   
 
I almost put this on another thread that dealt with similiar results, but didn't because I figured I should stay with my own and not confuse people.

To prevent the code from getting called so quickly that it confuses itself, the trigger just logs the name into a list variable and if the db alias isn't running already, calls the alias.

The alias gets the information from the list variable, does it's thing, deletes that bit from the list, and then checks to see if the list variable is empty. If it is, then it stops, if it's not, then it takes the next in line and computes it.

so it's not messing up because it's getting overwhelmed. The list variable works great, I've had as many as 5 people in it at once with no problem. (And, ofc, I've had 1 person in it and it's hosed, or two, again there doesn't really seem to be a pattern)

k
Reply with quote
Pega
Magician


Joined: 08 Jan 2001
Posts: 341
Location: Singapore

PostPosted: Fri Apr 09, 2004 7:52 pm   
 
Yeah perhaps it has nothing to do with the handling of data in your script, but instead it has something to do with zMUD's synchronization with the external database controls. I thought that might help smoothen the flow of data. Anyway I am still looking for a good solution too.
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