Front page | perl.dbi.users |
Postings from July 2006
CURSOR WITH UPDATE
Thread Next
From:
pDale
Date:
July 11, 2006 10:49
Subject:
CURSOR WITH UPDATE
Message ID:
5494c3ae0607111049r4c0da3cdk8c593325d140ebac@mail.gmail.com
From looking around with Google, it would APPEAR that you can
implement a cursor WITH UPDATE in DBI, but I have not been able to
find an example of that. Would anyone happen to have a bare-bones
code framework for such a thing?
Since I should give an example of the kind of operation I hope to do...
__CODE__
my $db; # database connection
my $match = "^H[ae]";
my $stmt = "SELECT foo,bar,fee FROM baz FOR UPDATE OF bar, fee";
my $sth;
die( "\nFailed preparing SELECT:\n$db->errstr\n" )
if !( $sth = $db->prepare($stmt) );
die( "\nFailed executing SELECT:\n$db->errstr\n" )
if !$sth->execute();
while ( my ( $foo, $bar, $fee ) = $sth->fetchrow_array )
{
next if $foo !~ /$match/;
$db->do( "UPDATE baz SET bar=3,fee='fie' WHERE CURRENT OF $sth->cursor")
or die( "UPDATE FAILED: $sth->errstr\n");
}
$sth->finish;
__CODE_ENDS__
Of course, $sth->cursor don't really exist (as far as I know).
TIA!
--
pDale Campbell
Thread Next
-
CURSOR WITH UPDATE
by pDale