these options will be cleared before setting the new ones, regardless of
whether any options are specified in the new C<connect_info>.
+Important note: DBIC expects the returned database handle provided by
+a subref argument to have RaiseError set on it. If it doesn't, things
+might not work very well, YMMV. If you don't use a subref, DBIC will
+force this setting for you anyways. Setting HandleError to anything
+other than simple exception object wrapper might cause problems too.
+
Examples:
# Simple SQLite connection
$self->_verify_pid if $self->_dbh;
$self->_populate_dbh if !$self->_dbh;
my $dbh = $self->_dbh;
- local $dbh->{RaiseError} = 1;
- local $dbh->{PrintError} = 0;
if($want_array) {
@result = $todo->($dbh);
}
: $self->_populate_dbh;
my $dbh = $self->_dbh;
- local $dbh->{RaiseError} = 1;
- local $dbh->{PrintError} = 0;
return $todo->($dbh);
}
}
eval {
- $dbh = ref $info[0] eq 'CODE'
- ? &{$info[0]}
- : DBI->connect(@info);
+ if(ref $info[0] eq 'CODE') {
+ $dbh = &{$info[0]}
+ }
+ else {
+ $dbh = DBI->connect(@info);
+ $dbh->{RaiseError} = 1;
+ $dbh->{PrintError} = 0;
+ }
};
$DBI::connect_via = $old_connect_via if $old_connect_via;
sub DESTROY {
my $self = shift;
- return if $self->_dbh;
+ return if !$self->_dbh;
$self->_verify_pid;
$self->_dbh(undef);