You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Vladislav Safronov <vl...@comptek.ru> on 2000/08/15 13:26:03 UTC

Question about $sth->finish;

Hi,

Could you have a look at the lines and answer the question ..
---
sub foo {
	my $dbh = shift;

	my $sql = ...

	my $sth = $dbh->prepare($sql);
	$sth->execute;
	$sth->finish;
}
===
Do I always need to call $sth->finish? Wouldn't it be automaticly called
when
sub foo ends (when my variable $sth get destroyed)?

Vlad.


RE: Question about $sth->finish;

Posted by Vladislav Safronov <vl...@comptek.ru>.
> On Tue, Aug 15, 2000 at 03:26:03PM +0400, Vladislav Safronov wrote:
> > Hi,
> > 
> > Could you have a look at the lines and answer the question ..
> > ---
> > sub foo {
> > 	my $dbh = shift;
> > 
> > 	my $sql = ...
> > 
> > 	my $sth = $dbh->prepare($sql);
> > 	$sth->execute;
> > 	$sth->finish;
> > }
> > ===
> > Do I always need to call $sth->finish?
> 
> You *never* need to call finish on non-select statements.
> (If you do, it's a driver bug.)
> 
> > Wouldn't it be automaticly called when
> > sub foo ends (when my variable $sth get destroyed)?
> 
> Finish marks the end of *fetching*, not the end of life of the handle.

So I can freely overwrite the handle with new one, since it's not the end
of life of the handle, can't I?
==
 	my $sql = "select .."
 
 	my $sth = $dbh->prepare($sql);
 	$sth->execute;
	.. fetch just some (not all) data
	my $newsql = "select .."
	$sth = $dbh->prepare($newsql);
 	$sth->execute;
==
and this code should work with troubles ...

Vlad.

Re: Question about $sth->finish;

Posted by Tim Bunce <Ti...@ig.co.uk>.
On Tue, Aug 15, 2000 at 03:26:03PM +0400, Vladislav Safronov wrote:
> Hi,
> 
> Could you have a look at the lines and answer the question ..
> ---
> sub foo {
> 	my $dbh = shift;
> 
> 	my $sql = ...
> 
> 	my $sth = $dbh->prepare($sql);
> 	$sth->execute;
> 	$sth->finish;
> }
> ===
> Do I always need to call $sth->finish?

You *never* need to call finish on non-select statements.
(If you do, it's a driver bug.)

> Wouldn't it be automaticly called when
> sub foo ends (when my variable $sth get destroyed)?

Finish marks the end of *fetching*, not the end of life of the handle.

Reread the DBI 1.14 docs on finish and tell me if anything is unclear.

Tim.

p.s. If someone asked me what I'd change about the DBI I was to rewrite
it, I'd probably just say "rename finish to cancel_select".

Re: Question about $sth->finish;

Posted by Matt Sergeant <ma...@sergeant.org>.
On Tue, 15 Aug 2000, Keith G. Murphy wrote:

> (Boggle)  Really? 'My' variables going out of scope don't always get
> freed up?  Or is this strictly an object thing with DESTROY?

Well why would you care if my $str = "hello world" didn't get freed via
this bug? It only matters for objects that do something in DESTROY...

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org


Re: Question about $sth->finish;

Posted by "Keith G. Murphy" <ke...@mindspring.com>.
Matt Sergeant wrote:
> 
> On Tue, 15 Aug 2000, Vladislav Safronov wrote:
> 
> > Hi,
> >
> > Could you have a look at the lines and answer the question ..
> > ---
> > sub foo {
> >       my $dbh = shift;
> >
> >       my $sql = ...
> >
> >       my $sth = $dbh->prepare($sql);
> >       $sth->execute;
> >       $sth->finish;
> > }
> > ===
> > Do I always need to call $sth->finish? Wouldn't it be automaticly called
> > when
> > sub foo ends (when my variable $sth get destroyed)?
> 
> $sth doesn't always get destroyed when foo ends (due to a bug in all
> perls).

(Boggle)  Really? 'My' variables going out of scope don't always get
freed up?  Or is this strictly an object thing with DESTROY?

RE: Question about $sth->finish;

Posted by Matt Sergeant <ma...@sergeant.org>.
On Tue, 15 Aug 2000, Vladislav Safronov wrote:

> "my" (perl's my) variables doesn't always get destoyed, does it???? Perl's 
> documentation say that "my" vars are the most safe since they get destroyed
> when they get out of scope ...

I said this was a bug in Perl, although I don't think that 5.6.1 is fixing
it (due out "soon"), because its quite hard to track down. It occurs in
conditionals:

if (my $rec = foo()) {
	# lexicals in foo() not destroyed here
}
# lexicals in foo() destroyed here.

This can be demonstrated with a very simple object class with a DESTROY
method. There's a message somewhere in the p5p archives about this from
me.

(and I don't mean the lexicals that might get returned and assigned to
$rec, for anyone assuming I don't know what I'm talking about)...

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org


RE: Question about $sth->finish;

Posted by Vladislav Safronov <vl...@comptek.ru>.
> On Tue, 15 Aug 2000, Vladislav Safronov wrote:
> 
> > Hi,
> > 
> > Could you have a look at the lines and answer the question ..
> > ---
> > sub foo {
> > 	my $dbh = shift;
> > 
> > 	my $sql = ...
> > 
> > 	my $sth = $dbh->prepare($sql);
> > 	$sth->execute;
> > 	$sth->finish;
> > }
> > ===
> > Do I always need to call $sth->finish? Wouldn't it be 
> automaticly called
> > when
> > sub foo ends (when my variable $sth get destroyed)?
> 
> $sth doesn't always get destroyed when foo ends (due to a bug in all
> perls). But otherwise, yes.

"my" (perl's my) variables doesn't always get destoyed, does it???? Perl's 
documentation say that "my" vars are the most safe since they get destroyed
when they get out of scope ...

Vlad.

Re: Question about $sth->finish;

Posted by Matt Sergeant <ma...@sergeant.org>.
On Tue, 15 Aug 2000, Vladislav Safronov wrote:

> Hi,
> 
> Could you have a look at the lines and answer the question ..
> ---
> sub foo {
> 	my $dbh = shift;
> 
> 	my $sql = ...
> 
> 	my $sth = $dbh->prepare($sql);
> 	$sth->execute;
> 	$sth->finish;
> }
> ===
> Do I always need to call $sth->finish? Wouldn't it be automaticly called
> when
> sub foo ends (when my variable $sth get destroyed)?

$sth doesn't always get destroyed when foo ends (due to a bug in all
perls). But otherwise, yes.

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org