|
Michael Nelson Novice
Joined: 03 Oct 2005 Posts: 36
|
Posted: 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 :) |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: 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.
|
|
|
|
Michael Nelson Novice
Joined: 03 Oct 2005 Posts: 36
|
Posted: Sat Nov 01, 2008 6:18 pm |
Thank you for your attention to this issue Zugg.
|
|
|
|
calesta Apprentice
Joined: 07 Dec 2008 Posts: 102 Location: New Hampshire, USA
|
Posted: 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? |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: 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 |
|
|
|
|
|