use DBI;
use Carp;
use English;
...
my $dbh = DBI->connect($self->{dburl}, $self->{dbuser}, $self->{dbpass
+word},
{
AutoCommit => 0, # This is a proper
+ database, not a key-value store
RaiseError => 0, # Child protection
+ mode off. We are doing our own error checking, thank you very much
AutoInactiveDestroy => 1, # Just do
+ the right thing when using fork()
}) or croak("$EVAL_ERROR");
...
# sub bla($dbh) {
my $selsth = $dbh->prepare_cached("SELECT foo, bar, baz FROM bli WHERE
+ bla = ? ORDER BY blub")
or croak($dbh->errstr); # If the statement is wrong, no point
+of internal error handling
if(!$selsth->execute("foobar")) {
$reph->debuglog($dbh->errstr);
$dbh->rollback;
return 0; # Tell caller we failed
}
# Work on the data row-by-row
while((my $line = $selsth->fetchrow_array)) {
...
# Do something with the data
...
}
$selsth->finish; # Make sure we don't leave database pointers and stuf
+f around
$dbh->commit; # Finish the current transaction, unlock all locked tabl
+es/rows and stuff.
# commit() may or may not happen in THIS function, depen
+ding on if the caller needs to
# chain multiple functions in a single transaction
return 1; # tell caller we succeeded.
...
|