On Fri, Jan 03, 2003 at 07:57:01AM -0800, Michael Peppler wrote:
> On Fri, 2003-01-03 at 02:42, Tim Bunce wrote:
> > On Fri, Jan 03, 2003 at 05:01:53AM +0200, Boris Penchev wrote:
> > > Dear All,
> > > 
> > > 1. Yes, I know that if you have prepare you can make a lot of execute of it, and 
>that i can make this query in start of my program
> > > or in one module.
> > > 2. I think that is a good idea to declare $id and $name in while loop, because I 
>use it only in this loop
> > > 3. I recommend you to use finish() method
> > 
> > I recommend you don't unless you know that the code will not read
> > all the rows that would be selected.
> 
> Unfortunately when using DBD::Sybase the following code breaks, even if
> there is only one row to fetch for the first iteration:
> 
> $sth = $dbh->prepare("select ... from ... where id = ?");
> $sth->execute(1);
> $row = $sth->fetch;
> $sth->execute(2);   # dies here.
> 
> The reason is that the Sybase client libraries (and DBD::Sybase) can
> only tell that *all* the results have been fetched once fetch() returns
> an empty/undef array.

Sure. That's true for most drivers. The 'Active' flag ($sth->{Active})
stays true until fetch() returns an empty/undef array, at which point
the driver should turn off the Active flag.

> Adding a  $sth->finish before the second execute() call fixes the
> problem, of course.

The DBD::Sybase execute() method should effectively call finish() if
the statement handle is 'Active' when execute is called. That's one
of the main reasons the flag exists at all.

Tim.

Reply via email to