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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Michael Nelson
Novice


Joined: 03 Oct 2005
Posts: 36

PostPosted: Sun Oct 12, 2008 10:31 pm   

Workaround for %query [Bug]
 
I am fairly certain %query() does not expand its string parameter. This had me pulling my hair out. They way I got around it is as follows:

Here is an example of a failed query,

queryString =%concat("&name=""", $area_name, """")
#show %query(@queryString)

This uses the literal value @queryString for the query thereby failing miserably.
This is the workaround,

$executestring = %concat("%query(&name =""",$area_name,""")")
#show %exec($executestring)

Hope this helps people who have were are flustered as me :)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Oct 13, 2008 4:39 pm   
 
You are correct. I just checked the command database for CMUD and verified that %query (and #QUERY) is taking a "literal" argument instead of a "string" argument. This prevents it from expanding variables. This has been fixed for the next version.
Reply with quote
Michael Nelson
Novice


Joined: 03 Oct 2005
Posts: 36

PostPosted: Sat Nov 01, 2008 6:18 pm   
 
Thank you for your attention to this issue Zugg.
Reply with quote
calesta
Apprentice


Joined: 07 Dec 2008
Posts: 102
Location: New Hampshire, USA

PostPosted: Sun Dec 14, 2008 3:35 pm   
 
I can use normal variables successfully in a query string, but local variables don't seem to work still (at least not directly in the query string).

Works:
Code:
target = Whitestorm
%query("&Location=@target")
%query(%concat("&Location=", $target))
%query(%concat("&Location=", %1))

Doesn't work:
Code:
$target = Whitestorm
%query("&Location=$target")
%query("&Location=%1")

I thought putting the query string in quotes would prevent all variable expansion, not just local variable expansion. Is the %query argument just an exception to that rule? If so, should it also be doing variable expansion for local variables?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Dec 14, 2008 10:33 pm   
 
The local variables will not expand in quotes. When %query actually does its thing is a little bit later, you could think of the %query function as a complex script that looks something like:
set db view
clear result
dbfirst
while rec do
if @originalQuery then add record number to result
db next
end
return result

When you consider it in that context the local variable is not actually in scope. Also I think %query doesn't know about local variables because it can't create/modify variables directly.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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