Forum OpenACS Development: Problem with using db_multirow in <package>-procs.tcl

Hello,

I'm trying to define a proc returning an ns_set, i.e. via set args [ns_set create].
This works fine for where I'm only to return one value from my queries, but I'm having problems getting instances of multiple rows returned in my adp's.

I've tried, namely: db_multirow pre_reqs pre_reqs_sql { }
Where pre_reqs_sql: select method from assessment where unit_code = :unit;

(Returning a list of assessment routines, given a course of study).
When trying to call this value back in my respective *.tcl, I get the error that the multirow-ed variable cannot be read, or it does not return any rows (although it does, as I call it with the multiple tag in my adp, using the same query in the tcl layer and it works fine).

I've looked through the documentation of upvar and uplevel, but am not entirely sure this method would be the right approach - although it looks as though I'd be heading that way, short of keeping all queries and multirow-ed attributes purely in my respective *.adp, *.tcl and *.xql files.

I have also tried db_list to set the return value and, while it works, the formatting isn't what I'm after (for the display view to be put in a course book format).

Any help would be greatly appreciated, as to whether I'm using the right approach, etc.

Cheers

Collapse
Posted by Dave Bauer on
Normally the pattern for upvaring a multirow works like this:

ad_proc -public my::proc {
    {-multirow_name "varname"}
} {
    upvar $varname local_var
    db_multirow local_var queryname "*SQL*"
}

What this does is take the name of a variable in the callers scope. It creates this variable which will be used as the multirow reference.

Collapse
Posted by Jon Suen on
Thanks for your help.
Are you saying -multirow_name "varname" is defined in a separate code block to the rest?

At the moment my understanding of the syntax for procs generally is:

ad_proc -public processname {
{-parameters_passed_in:required,etc.}
} { Documentation
} {

# Code block (main body for the procedure)

return $args
# for example

}

Is this correct? I'm just not entirely clear on where
{-multirow_name "varname"}
would fit in, if not within the main body.

I'll give it a go all the same, thanks again.

Jon

At present I have:

{ -multirow_name "prs" }


{ upvar $prs prs

db_multirow prs pre_reqs_sql { }
}

### And I define pre_reqs_sql to return a multirow-ed
### value in the according package-procs.xql file.

This currently spits up a request error:
[snip]
invalid command name "-multirow_name "prs""
[/snip]

Which I didn't really expect to work all the same, since I'm not sure about the placement of the -multirow_name switch...

Any help would be greatly appreciated

Cheeres

Hi,

I don't know if this problem is still a current one, but by replacing

upvar $varname local_var
db_multirow local_var queryname "*SQL*"

to

upvar $multirow_name local_var
db_multirow local_var queryname "*SQL*"

the whole thing works pretty fine.