Forum OpenACS Q&A: Re: Getting the SQL from the .XQL

Posted by John Sequeira on
If statement_name is the name of the query you're trying to resolve, use:

set pre_sql "";  #default value
set full_statement_name [db_qd_get_fullname $statement_name]
set sql [ db_qd_replace_sql $full_statement_name $pre_sql] 

You have to do this in the file with the same name as the xql so that it resolves correctly.

Posted by Paul Cannon on
This won't work from the file with the same name as the xql, because db_qd_get_fullname requires a certain level between it and that file. If you do want to use it directly, pass a 0 as the second parameter so that it can uplevel to the right place. Example:

set full_statement_name [db_qd_get_fullname $statement_name 0]
set sql [db_qd_replace_sql $full_statement_name $pre_sql]

Of course, the db_map option is probably a better one.