Forum OpenACS Development: "faking" columns in an ACS4 db_multirow

Collapse
Posted by russ m on

This question is actually in relation to aD ACS4.2, but I suspect there's a little more TCL community around here...

I want to add in TCL a column to the result set returned by db_multirow, or prehaps munge (once again, in TCL) one of the columns returned. The technique I've come up with uses a bit too much knowledge of the internal representation of these result sets for my liking - surely there must be a cleaner way.

db_multirow assets assets {
  select a.asset_id, a.filename
  from qx_assets a
  where whatever = something else
} {
  upvar #[template::adp_level] "assets:[expr {${assets:rowcount} + 1}]" assets
  set assets(thumb_url) [qx_asset_url $asset_id thumb $filename]
}

here the function qx_asset_url takes the asset_id and filename results from the query and returns a bit of text which appears to the template to be an additional column, thumb_url. Is this really the best/only way of doing this?

Collapse
Posted by Gilbert Wong on

Try looking here: http://developer.arsdigita.com/doc/acs-templating/api/multirow.html

I've used the multirow functions to process the output of db_multirow. I had to do some processing in TCL for one of my columns in a result set before I could use the datasource in the .adp page. I used multirow size, multirow get, and multirow set in a loop outside of the db_multirow call to directly access the column names/values.

I hope this helps.

Collapse
Posted by russ m on

I'd be more likely to use a multirow create / db_foreach / multirow append rather than a seperate loop to tack on another column "after the fact". I guess my point is that db_multirow has provision for a TCL block that gets evaluated for each row, and makes column values available in that scope, which seems so close to what I'm after that I can't help feeling that I've missed something obvious.

Here is how I like to do it:
set sql "select first_names, last_name from users"

set extra_eval "set row(whole_name)  "$row(first_names) 
$row(last_names)" "

template::query users multirow $sql -db  $db  -eval $extra_eval
This should do exactly what you want, and make a @users.whole_name@ available in the .adp
Collapse
Posted by Graeme Walters on
I use a dummy column in the query --

db_multirow my_file {
  select id, name, '' as href from my_file
} {
  set href "edit?id=$id"
}