[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] SQL value in [perl]?
> Just a quickie. I'm new at Perl but I'm doing okay. When I access a scratch
> value in a [perl] tag, I access it like thus:
>
> my $NewString = $Scratch->{my_value};
>
> But how do I access the value I would get from a query list, like [sql-param
> my_value]? I've tried a few things, and can't seem to find it in the docs.
> I've tried:
>
> my $NewString = $Sql-param ->{raw_brand};
>
A Perl equivalent of [sql-param] is not available, but you could use
the following as an example of what you could do instead.
[query arrayref=somename sql=|
SELECT col1, col2
FROM tablename
WHERE foo = 'bar'
|][/query]
[perl tables="tablename"]
my $resultset = $Tmp->{'somename'};
foreach my $line (@$resultset){
# $line->[0] is col1
# $line->[1] is col2
}
undef;
[/perl]
Or you could get rid of the [query] tag by doing something like the
following:
[perl tables="tablename"]
my $query = qq{
SELECT col1, col2
FROM tablename
WHERE foo = 'bar'
};
my $dbh = $Sql{'tablename'} or die 'Bad DB handle';
my $resultset = $dbh->selectall_arrayref($query) or die 'Cannot perform
SELECT';
foreach my $line (@$resultset){
# $line->[0] is col1
# $line->[1] is col2
}
undef;
[/perl]
--
_/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
_/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h
_/ _/ _/ _/ _/ _/ _/ _/_/ kevin@cursor.biz
_/ _/ _/_/_/_/ _/ _/_/_/ _/ _/