[ic] SQL inside UserTags
Stefan Hornburg
interchange-users@icdevgroup.org
Fri Apr 4 11:48:00 2003
On 04 Apr 2003 17:02:35 +0100
Andy Mayer <andy@andymayer.net> wrote:
> Hi there,
>
> I am trying to perform an SQL query inside a usertag, and I am having
> difficulty finding complete examples in the documentation.
>
> Could somebody please post an example of a usertag that:
>
> 1. Selects a data from a single table
> 2. Outputs the result from the UserTag
>
> I have started with the following code, but I can't figure out how to
> access the query results and work out how many rows returned etc.
>
> --------
> my $sql = "select c_author from c_people";
> my $result_array = $Tag->query( { wantarray => 1, sql => $sql, }, $body
> );
> my ($same_results, $col_name_hash, $col_name_array) =
> $Tag->query( { sql => $sql, },
> $body );
> my $result_hasharray = $Tag->query( { sql => $sql,
> hashref => 'my_results', },
> $body );
> --------
>
> Please be gentle, as I am not hardcore perl.... yet ;)
Most straightforward:
# enable access to table
$Tag->perl({tables=>'products'});
# query
$set = $Db{products}->query('select * from products where color = "green"');
# result count
$count = @$set;
# loop
for (@$set) {
$sku = $_->[0];
}
Ciao
Racke