my $dbh = DBI->connect( $connect_string, $user, $password, { RaiseError => 1, PrintError => 0, AutoCommit => 0, } ); sub insertRecord { my ($record, $dbh, $tapeID) = @_; my %max = getMaxID($dbh); eval { my $sth = $dbh->prepare_cached(addressQuery()); $sth->execute( $max{'addresses'}, ( map { $record->{"subscriber_$_"} qw( address_one address_two city state zip zip4 )), $tapeID, ); ##Execute more queries in the same fashion $dbh->commit(); } if ($@) { $dbh->rollback; return 0; } return 1; }
I also added a few changes to your syntax, which improves the readability. (In my opinion, of course. They are functional-neutral to what you had, which worked just fine.)
Well, mostly worked fine. Your syntax implied that you were passing a reference to the $dbh into your subroutine. There is no reason to do that, as it's already a reference. If you're not doing that, you have a potential error.
Update: Added a sample $dbh definition with the appropriate settings.
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
In reply to Re: Managing DBI Transactions
by dragonchild
in thread Managing DBI Transactions
by Grygonos
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |