[ic] assign Query-Result-Row to Usertag
Chris Kershaw
chris at endpoint.com
Thu Oct 22 19:08:33 UTC 2009
Rick Bragg wrote:
> On Thu, 2009-10-22 at 16:50 +0200, Ingo Buse wrote:
>
>> Hi,
>>
>> i am having problems understanding the documentation, so maybe u guys may help me out with an example ?
>>
>> what I want is to forward a result-row of a [query] to my custom made UserTag. I did not really understood the wantarray/hashref stuff.
>>
>> the query in question also implements a more list and will simply select from products:
>>
>> [query type=list more=1 ml=10 sql="select * from products where ...."]
>> [list]
>> [/list]
>> [more-list]
>> [/more-list]
>> [/query]
>>
>> Now I just want to forward the whole sql-result-row (each product) as hash or array to my UserTag maybe like this:
>> [myusertag [item]]
>>
>> So I can refer to the position or the name of the column in the databases of that item.
>>
>> UserTag myusertag Routine <<EOR
>> sub {
>> my ($item, $opt) = @_;
>> my $productname = $item->{name};
>> my $price = $item->{price};
>> ...
>> my $description = $item->[3];
>> }
>>
>> So if I extend the Database by a column, I can "automagically" refer to that column in my Usertag (if I do a "select *" offcourse).
>>
>> Is that possible ?
>>
>> --
>> Ingo
>>
>>
>
>
> That could be a bit dangerous. For example somebody adds a blob field
> to the table for large binary files... I think it's always best to
> always SELECT only, what, you, need FROM tables.
>
>
>
Hello Ingo,
There are a couple of ways that I have done something similar. I prefer
to use PREFIX-sub myself, but something along these lines should work.
Option 1
[query
type=list
hashref=foo
sql="SELECT column1, column2, column3 FROM table WHERE ..."
]
[sql-list]
[perl]
my $output;
my $ref = $Tmp->{foo};
for my $item (@$ref) {
$output .= qq~sku: $item->{column} price: $item->{column}~;
}
return $output;
[/perl]
[/sql-list]
[/query]
OR Option 2 with PREFIX-sub
[query
type=list
hashref=foo
sql="SELECT column1, column2, column3 FROM products WHERE ..."
]
[sql-list]
[sql-sub show_info]
my $ref = $_[1];
return qq~sku: $ref->{column} price: $ref->{column}~;
[/sql-sub]
[sql-exec show_info][/sql-exec]
[/sql-list]
[/query]
Hope this helps
Chris
--
Chris Kershaw
End Point Corp.
Direct Line: 919-249-5356
Fax: 866-281-1373
http://www.endpoint.com
More information about the interchange-users
mailing list