in reply to Re: Recursive dbh executions
in thread Recursive dbh executions
The statement handle is still open in your snippet, isn't it? If so, nothing was saved. The handle could be closed like this:
... $sth->execute($objid); my @rows = @{$sth->fetchall_arrayref()}; $sth->finish(); foreach $row (@rows) { ...
But then one has to wonder why recursion is needed at all. We could reuse the prepared statement if we got rid of recursion:
Sub GetChildren{ my ($objid) = @_; my $sth = $dbh->prepare(<<' ;'); SELECT objid, type FROM table WHERE parentid=? ; # Initial fetch. $sth->execute($objid); @rows = @{$sth->fetchall_arrayref()}; while (@rows) { my ($objid, $type) = @{shift(@rows)}; if ($type eq "Container") { # Add to todo list. $sth->execute($objid); push(@rows, @{$sth->fetchall_arrayref()}); next; } do something else } $sth->finish(); }
Note: "=" was used to compare strings. "=" is the assignment operator. "==" is the numerical equivalency operator. "eq" is the string equivalency operator. "eq" is therefore the one needed to check if the type is "Container".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Recursive dbh executions
by VSarkiss (Monsignor) on Mar 23, 2005 at 16:19 UTC |