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
Theragil
Apprentice


Joined: 13 Feb 2004
Posts: 157
Location: USA

PostPosted: Sun Sep 09, 2007 3:21 am   

Database scripting: #dbdelete and %query() troubles
 
I've built a pretty large crafting system using the database module of zMUD and most of it works pretty well, but I have two problems that I can't make heads or tails of.

1) #dbdelete simply doesn't do anything for me and I have no idea why. I only use it in one place where I save the results of a %query() in a variable, then loop over it in a #forall and do #dbdelete %i. The values of %i are the right values (of the format "123wo"), but the #dbdelete line just doesn't do anything, and I can't see why. I've tried different combinations of #dbreset, #dbfirst, #dbload, and #dboffline before and during, but nothing changes the outcome. Any ideas?

2) I use %query() extensively, including a klugy mess where I build a %query() dynamically, and it works for me (with adequate use of #dbreset and such) in all but one place, where I'm checking an ID number to see if it's in the database. Using the exact same code, or using a simpler form (#if (%query( &ID = %1) = "")), either way I get inconsistent results. %1 definitely holds the right values but the query sometimes returns null even when the ID is in the database. Sometimes, but not always, and completely inconsistently; passing through the same list of IDs twice, I can have it misfire 1/2 the time once, not at all another time, and midway between a third. If I double the query (#if (%query( &ID = %1) = "" and %query( &ID = %1) = "")) it'll misfire less often on average... how can that be? Anyone know of any gotchas I might be getting bit by, or a workaround?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Sep 09, 2007 3:58 am   
 
The #DBDELETE issue is likely a bug. While the command has been around since the introduction of the database module I don't think anyone ever used it.

My best guess on the %query problem is that sometimes the %rec predefined variable has a value, and since ID is a field it occasionally is expanding the &ID portion of the expression based on the value of %rec. I know it is wierd for it to do this part of the time even when doubling up the queries with an AND. I would suggest trying '#IF (%query("&ID=%1")="")'. The reason this should work is that the parameter list for %query from the Function Wizard shows that the first paremeter is an Expression; making it subject to various types of expansion and evaluation before it gets intpretted by the function. By surrounding it in quotes we eliminate that unwanted behavior, and make use of the fact that zMud will substitute the %nn reference even in quotes.

An even more proper syntax would be #IF (%query(%concat("&ID=",%char(34),%1,%char(34)))) which makes the query parameter (&ID="actual %1 value"). In one case we surrounded the entire string with quotes so query did the evaluation, in the other the concat effectively does that part and additional quotes are passed within the query parameter.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Theragil
Apprentice


Joined: 13 Feb 2004
Posts: 157
Location: USA

PostPosted: Sun Sep 09, 2007 4:22 am   
 
Is there any other way to delete records under script control?

I'll give the %query() thing a try tomorrow. Thanks for the explanation, it makes sense.
Reply with quote
Theragil
Apprentice


Joined: 13 Feb 2004
Posts: 157
Location: USA

PostPosted: Sun Sep 09, 2007 1:13 pm   
 
The alternate %query() thing isn't helping. I added some debug code and found something odd. Every entry in my database has a unique ID but this query:
%query( %concat( "&ID=", %char( 34), %1, %char( 34)))
either returns nothing or everything, it never returns just the one item it should. But if I just type
#show %query(&ID=4348)
I get the proper result.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Sep 09, 2007 2:34 pm   
 
I just checked through one of my old scripts that made some farily heavy database usage and found I had no problems with straight forward forms of query. There seems to be no expansion or evaluation problems with it. This makes my guess above is totally erronius. The only thing that leaves is the value of %1, which you stated with certainty is correct at the query. I can say I am stumped without something more to go on.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Theragil
Apprentice


Joined: 13 Feb 2004
Posts: 157
Location: USA

PostPosted: Sun Sep 09, 2007 2:54 pm   
 
What seems to be working now is this:

tempvar = %concat( "%query(&ID=", %1, ")")
#if (@tempvar = "") {...}

If I build only the inside of the %query it still evaluates &ID too early. I have to build the whole %query and then when I check the variable it evaluates it anyway.
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