John, On 04-Jul-2006 John Scoles wrote: > Yes "execute_array" is a special case. > > What DBI does is pass the Array of Tuples off to the native array interface > of the database for processing and expects back a Tuple of results.
As an aside, I'm not sure this is always the case. I'm sure I read in the DBI docs you could pass a function reference in which would be used to retrieve the tuples. > Not sure what the exact call is in MYSQL but I know for Oracle this is what > OCI (the native Oracle interface) is doing. So it is a case of DBI::DBD > mimicking what the native driver is doing. > > As execute_array is normally use to inserts/update of millions of records > and with this volume you would not want your process to choke on just one > bad record so it makes sense to look for errors after the process has run > rather that stopping at each one. > > This being said if the DBD driver does not support an array interface DBI > simply mimics this behaviour by iterating though the array. Not real time > saving there it just follows the array interface model. > > Cheers > > John Scoles Thanks for the explanation. You have not however convinced me this behavior is right. If RaiseError caused a die on error and someone wanted to ignore errors they could just do what they always do - turn RaiseError off and do the checking themselves. What I was really after was whether not dying on an error in execute_array when RaiseError was enabled was by design or a an oversight. It makes a difference to me since I read the DBI docs and saw nothing which said RaiseError does not work with execute_array, then discovered it didn't, worked around this in my DBIx extension but would like to document why I have this workaround. Martin -- Martin J. Evans Easysoft Ltd, UK http://www.easysoft.com > ----- Original Message ----- > From: "Martin J. Evans" <[EMAIL PROTECTED]> > To: <dbi-users@perl.org> > Sent: Tuesday, July 04, 2006 8:03 AM > Subject: Re: Is it correct that execute_array does not raise/print an error > > >> >> On 04-Jul-2006 John Scoles wrote: >> > It memory serves me correctly I think any errors that are generated is >> > stored in the ArrayTupleStatus have a parse through that array to see it > the >> > error is stored there. >> >> John, >> >> They are stored in the ArrayTupleStatus. I'm not saying I can't get them, > but I >> rather thought since they were errors that RaiseError would cause a die > and >> that my HandleError routine would be called - neither seems to occur. > Unless >> I'm mistaken this seems to make execute_array a special case and thus >> RaiseError should say it causes a die for all error in methods except >> execute_array (and similarly for HandleError). >> >> Martin >> -- >> Martin J. Evans >> Easysoft Ltd, UK >> http://www.easysoft.com >> >> > >> > ----- Original Message ----- >> > From: "Martin J. Evans" <[EMAIL PROTECTED]> >> > To: <dbi-users@perl.org> >> > Sent: Tuesday, July 04, 2006 6:37 AM >> > Subject: Is it correct that execute_array does not raise/print an error >> > >> > >> >> Hi, >> >> >> >> I have some code which uses execute_array but it appears when it fails >> >> my error handler is not called and no error is printed despite setting >> >> PrintError and RaiseError. The script below illustrates. Is it correct >> > that an >> >> error can occur in execute_array and it not cause a die when RaiseError > is >> > set? >> >> >> >> use DBI; >> >> use strict; >> >> use Data::Dumper; >> >> >> >> sub fred >> >> { >> >> print "Error Handler called\n"; >> >> print Dumper([EMAIL PROTECTED]); >> >> } >> >> >> >> my $dbh = DBI->connect( >> >> 'DBI:mysql:mjetest', 'xxx', 'yyy', >> >> { RaiseError => 1, PrintError => 1, HandleError => \&fred}); >> >> $dbh->do(q/drop table if exists mytest/); >> >> $dbh->do(q/create table mytest (a int primary key, b char(20))/); >> >> >> >> my $sth = $dbh->prepare(q/insert into mytest values (?,?)/); >> >> $sth->bind_param(1, 1); >> >> $sth->bind_param(2, 'onetwothree'); >> >> $sth->execute; >> >> >> >> $sth->bind_param_array(1, [51,1,52,53]); >> >> $sth->bind_param_array(2, ['fiftyone', 'fiftytwo', 'fiftythree', > 'one']); >> >> my @tuple_status; >> >> my $inserted = $sth->execute_array( { ArrayTupleStatus => >> > [EMAIL PROTECTED] } ); >> >> print "Error from execute_array - $DBI::errstr\n" if (!$inserted); >> >> >> >> which produces: >> >> >> >> Error from execute_array - >> >> >> >> even though the trace indicates: >> >> >> >> <- prepare('insert into mytest values (?,?)')= > DBI::st=HASH(0x82a1b80) >> > at >> >> execute_array.pl line 17 >> >> <- bind_param(1 1)= 1 at execute_array.pl line 18 >> >> <- bind_param(2 'onetwothree')= 1 at execute_array.pl line 19 >> >> <- execute= 1 at execute_array.pl line 20 >> >> <- bind_param_array(1 ARRAY(0x829d4f8))= 1 at execute_array.pl line > 22 >> >> <- bind_param_array(2 ARRAY(0x829d534))= 1 at execute_array.pl line > 23 >> >> <- execute_array(HASH(0x829d5c4))= undef at execute_array.pl line > 26 >> >> >> >> >> >> Thanks >> >> >> >> Martin >> >> -- >> >> Martin J. Evans >> >> Easysoft Ltd, UK >> >> http://www.easysoft.com >> >> >> >> >> >>