[Cascavel-pm] Duvida STH->execute
Igor Sutton Lopes
igor.sutton em yahoo.co.uk
Quarta Agosto 8 10:04:54 PDT 2007
On Aug 8, 2007, at 5:18 PM, Marco Lima wrote:
> Salve !
>
> ...
>
> my $sth = $dbh->prepare( qq{ SELECT campo1, campo2
> FROM teste
> WHERE datahora >= timestamp '2007-08-01
> 00:00:00' - internal '6 hour'
> ORDER BY datahora
> } );
> $sth->execute( );
>
> my $array_ref = $sth->fetchall_arrayref();
>
> $sth->finish( );
>
> $sth= $dbh->prepare( qq{ UPDATE tabela1
> SET teste='33333'
> WHERE id= ?
> AND datahora= ?
> } );
>
> foreach my $row ( @$array_ref ) {
> $sth->execute ( @$row );
> warn "Problema ao processar os resultados", $sth->errstr( ),
> "\n" if
> $sth->err( );
> }
Você pode também deixar de usar um statement handler caso você tenha
uma query estática:
<code>
my $array_ref = $dbh->selectall_arrayref(qq{ SELECT campo1, campo2
FROM teste WHERE datahora >= timestamp '2007-08-01 00:00:00' -
internal '6 hour' ORDER BY datahora } );
$sth= $dbh->prepare( qq{ UPDATE tabela1 SET teste='33333' WHERE id= ?
AND datahora= ? } );
foreach my $row ( @$array_ref ) {
$sth->execute ( @$row );
warn "Problema ao processar os resultados", $sth->errstr( ), $/
if $sth->err( );
}
</code>
Boa sorte!
Mais detalhes sobre a lista de discussão Cascavel-pm