"M. Addlework" <[EMAIL PROTECTED]> writes:

> > > Kristian Nielsen [EMAIL PROTECTED] wrote:
> > >> Could you briefly explain what an INSERT/UPDATE cursor is?

>       UPDATE <table> set <column> = <value> where CURRENT OF X;

> The original poster was correct that you can't do this directly in
> DBI.  However, below is a technique which is functionally identical:
> 
> $sth = $dbi->prepare("select ROWID, x.* from <table> x FOR UPDATE");
> $stu = $dbh->prepare("update <table> set <column> = <value> where ROWID = ?");
> 
> $sth->execute;
> while ($r = $sth->fetchrow_hashref) {
>      $stu->execute($r->{ROWID});
> }
> 
> This is essentially what's happening with the WHERE CURRENT OF clause.

Ah, I see. And with this technique (and a DBI driver with native
execute_array() support), you could even collect all the ROWIDs in an
array and do all the updates/deletes in a single execute_array() at the
end of the loop, avoiding having a database roundtrip for every
row. That ought to me much more effective for large row sizes,
especially if the client is running on a different machine than the
database server.

Thanks!

 - Kristian.

Reply via email to