|
yawdoolf Beginner
Joined: 21 Sep 2008 Posts: 10
|
Posted: 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. |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: 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! |
|
|
|
yawdoolf Beginner
Joined: 21 Sep 2008 Posts: 10
|
Posted: 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. |
|
|
|
wizzywoo Newbie
Joined: 17 Feb 2003 Posts: 5
|
Posted: 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}) |
|
|
|
|
yawdoolf Beginner
Joined: 21 Sep 2008 Posts: 10
|
Posted: 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? |
|
|
|
yawdoolf Beginner
Joined: 21 Sep 2008 Posts: 10
|
Posted: 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? |
|
|
|
|
|