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
yawdoolf
Beginner


Joined: 21 Sep 2008
Posts: 10

PostPosted: Sun Sep 21, 2008 2:18 pm   

Dynamic #query string. How?
 
Hello.

I need to query DB with non-static query string. For example, the following are static (I mean that I can only pass values to compare with but can't change comparing expression itself) queries:
Code:
#query (&Name = %1 & &Hit > %2)
#query (&Name > %1 & &Hit = %2)
...etc

I have a complex trigger where could be many parameters to be passed to #query.
So, I need something like that:
Code:
#query (%concat("&Name ",%1," '",%2,"'"))

Where %1 is comparator (=,<,>,etc) and %2 is value to compare with.

Another invoking of such trigger can cause comparing not only &Name but also &Hit and others.

It will be cool to combine several #query statements into the one big query (or some cascade principle). If it were possible I could code it without any %concat().

How can I do it?

ps. zMud 7.13.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sun Sep 21, 2008 3:31 pm   
 
You could probably do it two ways.

First you can build the query string dynamically, store it in a variable, that pass the variable into the #QUERY command.

Another approach is to also parameterize the fields you are looking up much like the you did the comparators.

Beyond that there no automated built-in function to do what you suggest. Out of curiousity, why aren't you using version 7.21?
_________________
Asati di tempari!
Reply with quote
yawdoolf
Beginner


Joined: 21 Sep 2008
Posts: 10

PostPosted: Mon Sep 22, 2008 8:55 pm   
 
Tech wrote:
First you can build the query string dynamically, store it in a variable, that pass the variable into the #QUERY command.
Like that?
Code:
#var myvar "&Name = 'staff'"
#query (@myvar)
But it doesn't work. And help doesn't cover such behavior of #(%)query statement.

Tech wrote:
Another approach is to also parameterize the fields you are looking up much like the you did the comparators.
The mentioned code with %concat() function is abstract and this is just an example. I would be happy if I could use it :)

If you can do it with zMud 7.21 show me an example code, please.
Reply with quote
wizzywoo
Newbie


Joined: 17 Feb 2003
Posts: 5

PostPosted: Mon Sep 22, 2008 10:08 pm   
 
I think your problem is that you have single quotes where they're not needed. A sample fairly complex query would look something like this:

Code:
tmpresult = %query( &player=@self AND &type=%key AND &location <> 0 AND &level <= @{status.current_level})
Reply with quote
yawdoolf
Beginner


Joined: 21 Sep 2008
Posts: 10

PostPosted: Mon Sep 22, 2008 10:16 pm   
 
wizzywoo wrote:
I think your problem is that you have single quotes where they're not needed.
It seems to work with single quotes but within explicit query.

wizzywoo wrote:
A sample fairly complex query would look something like this:
Code:
tmpresult = %query( &player=@self AND &type=%key AND &location <> 0 AND &level <= @{status.current_level})
Suppose you doesn't know what will the first comparator be (&player [=|<|>|!=|etc] @self). How would you code it?
Reply with quote
yawdoolf
Beginner


Joined: 21 Sep 2008
Posts: 10

PostPosted: Fri Sep 26, 2008 9:33 pm   
 
By the way, can I do it with JavaScript?
But I have no idea how to access zMud variables and invoke zMud commands like #query, etc.

Could somebody give me a clue about using JavaScript inside of zMud's triggers?
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