Re: Patch for undefined value error when zero bind values
On Mon, Jan 26, 2004 at 03:26:32PM -, Avis, Ed wrote: > [diff to DBI.pm] > > >+ ($tuple_status) ? @$tuple_status = () : $tuple_status = []; > > AFAIK this code is equivalent to > > @$tuple_status = (); > > because of autovivification. True. I prefer to make it explicit. I guess a comment that it autovivifies would have sufficed. Ho hum. Tim.
RE: Patch for undefined value error when zero bind values
[diff to DBI.pm] >+ ($tuple_status) ? @$tuple_status = () : $tuple_status = []; AFAIK this code is equivalent to @$tuple_status = (); because of autovivification. But anyway, it works. -- Ed Avis <[EMAIL PROTECTED]>
Re: Patch for undefined value error when zero bind values
On Mon, Jan 26, 2004 at 02:21:33PM -, Avis, Ed wrote: > Tim Bunce <[EMAIL PROTECTED]> wrote: > > >Actualy I did this instead, as it seems more correct: > > > >@@ -1720,5 +1721,6 @@ > > sub execute_for_fetch { > >my ($sth, $fetch_tuple_sub, $tuple_status) = @_; > >- @$tuple_status = () if $tuple_status; # reset the status array > >+ # start with empty status array > >+ ($tuple_status) ? @$tuple_status = () : $tuple_status = undef; > > But when I try that code it fails the tests I added. Uh, groan. The diff I pasted was an old one where I was rechecking that the tests failed by replacing [] with undef. This is the right diff hunk: @@ -1720,5 +1721,6 @@ sub execute_for_fetch { my ($sth, $fetch_tuple_sub, $tuple_status) = @_; - @$tuple_status = () if $tuple_status; # reset the status array + # start with empty status array + ($tuple_status) ? @$tuple_status = () : $tuple_status = []; my ($err_count, %errstr_cache); > Did you apply the patch to the test suite? Yes, thanks. (I just had too many windows with diff in them :) Tim.
RE: Patch for undefined value error when zero bind values
Tim Bunce <[EMAIL PROTECTED]> wrote: >Actualy I did this instead, as it seems more correct: > >@@ -1720,5 +1721,6 @@ > sub execute_for_fetch { >my ($sth, $fetch_tuple_sub, $tuple_status) = @_; >- @$tuple_status = () if $tuple_status; # reset the status array >+ # start with empty status array >+ ($tuple_status) ? @$tuple_status = () : $tuple_status = undef; But when I try that code it fails the tests I added. Did you apply the patch to the test suite? -- Ed Avis <[EMAIL PROTECTED]>
Re: Patch for undefined value error when zero bind values
On Mon, Jan 26, 2004 at 01:18:19PM +, Tim Bunce wrote: > Thanks, applied. > > Tim. > > On Mon, Jan 26, 2004 at 10:18:03AM -, Avis, Ed wrote: > > This patch to DBI-1.40 fixes an error > > > > Can't use an undefined value as an ARRAY reference at DBI.pm line 1735 > > > > when using execute_array() with zero values for a bind parameter. It > > includes some new test cases, but not all of the new tests failed > > before. > > > > diff -ru DBI-1.40/DBI.pm DBI-1.40-new/DBI.pm > > --- DBI-1.40/DBI.pm 2004-01-08 14:03:57.0 + > > +++ DBI-1.40-new/DBI.pm 2004-01-26 10:15:46.0 + > > @@ -1719,7 +1719,7 @@ > > > > sub execute_for_fetch { > > my ($sth, $fetch_tuple_sub, $tuple_status) = @_; > > - @$tuple_status = () if $tuple_status; # reset the status array > > + @$tuple_status = (); # reset the status array Actualy I did this instead, as it seems more correct: @@ -1720,5 +1721,6 @@ sub execute_for_fetch { my ($sth, $fetch_tuple_sub, $tuple_status) = @_; - @$tuple_status = () if $tuple_status; # reset the status array + # start with empty status array + ($tuple_status) ? @$tuple_status = () : $tuple_status = undef; I also spotted that the docs don't match the code so I changed the docs: -The number of tuples executed is returned, regardless of the success -or failure of those executions. Use tuple_status to check. +The number of tuples executed is returned I there were no errors. +If there were any errors then C is returned and the @tuple_status +array can be used to discover which tuples failed and with what errors. Thanks. Tim.
Re: Patch for undefined value error when zero bind values
Thanks, applied. Tim. On Mon, Jan 26, 2004 at 10:18:03AM -, Avis, Ed wrote: > This patch to DBI-1.40 fixes an error > > Can't use an undefined value as an ARRAY reference at DBI.pm line 1735 > > when using execute_array() with zero values for a bind parameter. It > includes some new test cases, but not all of the new tests failed > before. > > diff -ru DBI-1.40/DBI.pm DBI-1.40-new/DBI.pm > --- DBI-1.40/DBI.pm 2004-01-08 14:03:57.0 + > +++ DBI-1.40-new/DBI.pm 2004-01-26 10:15:46.0 + > @@ -1719,7 +1719,7 @@ > > sub execute_for_fetch { > my ($sth, $fetch_tuple_sub, $tuple_status) = @_; > - @$tuple_status = () if $tuple_status; # reset the status array > + @$tuple_status = (); # reset the status array > > my ($err_count, %errstr_cache); > while ( my $tuple = &$fetch_tuple_sub() ) { > diff -ru DBI-1.40/t/15array.t DBI-1.40-new/t/15array.t > --- DBI-1.40/t/15array.t 2003-08-20 01:15:34.0 +0100 > +++ DBI-1.40-new/t/15array.t 2004-01-26 10:15:15.0 + > @@ -3,7 +3,7 @@ > use strict; > use Test; > > -BEGIN { plan tests => 34 } > +BEGIN { plan tests => 39 } > > use Data::Dumper; > $Data::Dumper::Indent = 0; > @@ -68,6 +68,25 @@ > $dumped = Dumper($tuple_status); > ok( $dumped, "[1,1,1]"); > > +# --- with no values for bind params, should execute zero times > + > [EMAIL PROTECTED] = (); > +ok( $sth->execute_array( { ArrayTupleStatus => $tuple_status }, > +[], [], [], [], > +), > +0); > +ok( @$rows, 0 ); > +ok( @$tuple_status, 0 ); > + > +# --- catch 'undefined value' bug with zero bind values > + > [EMAIL PROTECTED] = (); > +my $sth_other = $dbh->prepare("insert", { > + rows => $rows, # where to 'insert' (push) the rows > + NUM_OF_PARAMS => 1, > +}); > +ok( $sth_other->execute_array( {}, [] ), 0 ); > +ok( @$rows, 0); > > # --- ArrayTupleFetch code-ref tests --- > > > -- > Ed Avis <[EMAIL PROTECTED]>