in reply to Re: Handling a Database Error
in thread Handling a Database Error
my $q = 'INSERT INTO some_table (data) VALUES (?)'; my $sth = $dbh->prepare($q); { local $dbh->{RaiseError} = 1; while(my $data = $csv->get_next_line()) { eval{ $sth->execute($data); } if($@) { next; } # More code here... } }
Of course, with RaiseError set to false, you can also do the more readable:
It's up to you and the style you choose to work with. Either way, be consistent. (You wrap your execute(), but not your prepare() ... tsktsk!)while ( my $data = ... ) { $sth->execute( $data ) or next; }
|
|---|