On Mon, Oct 27, 2003 at 04:50:18PM +0100, Steffen Goeldner wrote:
> Tim Bunce wrote:
> > 
> > On Fri, Oct 24, 2003 at 11:00:55AM +0200, Steffen Goeldner wrote:
> > > Is there any value in returning a value (pun intended)
> > > from STORE? E.g.:
> > >
> > >   sub STORE  {
> > >     ...
> > >     return 1;
> > >
> > > For dbd_db_STORE_attrib(), DBI::DBD states:
> > >
> > >   The return value is TRUE if you have handled the
> > >   attribute or FALSE otherwise.
> > 
> > That's needed so the Driver.xst code knows if it should
> > then call SUPER::STORE.
> > 
> > > Does the same rule apply to STORE()? If so, where
> > > is the returned value used?
> > 
> > The only way for an application to get the return value is by calling
> > STORE explicitly. I guess that might be useful in some situations.
> 
> Three cases cross my mind:
> 
>  1) Return nothing (or an arbitrary value), i.e. the caller shouldn't
>     use that value.
> 
>  2) Return a boolean value, indicating success or failure.
> 
>  3) Return the new value.
> 
> Tim, can you settle on one of these cases?

I think it has to be 1 unless the driver docs indicate otherwise.

> If so, I'd like to include your recommendation into DBI::DBD.

Thanks.

> BTW: Case 1, something like that:
> 
>   sub STORE  {
>     ...
>     $dbh->SUPER::STORE($attr, $val);
>     return;
>   }
> 
> seems to collide with current practice:
> 
>   sub begin_work {
>     ...
>     $dbh->STORE('BegunWork',  1);
>   }
> 
>   $rc  = $dbh->begin_work   or die $dbh->errstr;

That's a bug. I've changed begin_work to return 1 instead of falling
off the end.

> P.S.: Funny, a similar question entered the p5p mailing-list
> 
>   <http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2003-10/msg01249.html>

Here's the proof from a trace (with a few lines deleted):

$ DBI_TRACE=2 perl -MDBI -e '$a = DBI->install_driver("mysql")->{foo}=1'
    -> DBI->install_driver(mysql) for freebsd perl=5.006001 pid=24349 ruid=307 euid=307
    <- install_driver= DBI::dr=HASH(0x81ba9b0)
    -> STORE in DBD::_::common for DBD::mysql::dr (DBI::dr=HASH(0x810709c)~INNER 'foo' 
1)
    <- STORE= '' at -e line 1
    -> FETCH in DBD::_::common for DBD::mysql::dr (DBI::dr=HASH(0x810709c)~INNER 'foo')
    <- FETCH= undef at -e line 1

note that the FETCH is skipped in a void context:

$ DBI_TRACE=2 perl -MDBI -e 'DBI->install_driver("mysql")->{foo}=1'
    -> DBI->install_driver(mysql) for freebsd perl=5.006001 pid=24348 ruid=307 euid=307
    <- install_driver= DBI::dr=HASH(0x81ba9b0)
    -> STORE in DBD::_::common for DBD::mysql::dr (DBI::dr=HASH(0x81070b4)~INNER 'foo' 
1)
    <- STORE= '' at -e line 1

I should add some notes about that to the docs. It has interesting
knock-on issues in relation to a) testing an attribute assignment,
and b) performance impact.

Thanks.

Tim.

Reply via email to