Lines 642-659
This method connects to the SQL database
Link Here
|
642 |
|
642 |
|
643 |
sub _connect_db { |
643 |
sub _connect_db { |
644 |
my ($self) = @_; |
644 |
my ($self) = @_; |
|
|
645 |
my $dbh; |
645 |
|
646 |
|
646 |
$self->{_dbh} = undef; |
647 |
$self->{_dbh} = undef; |
647 |
|
648 |
|
648 |
# Turn off PrintError and explicitly set AutoCommit to off |
649 |
if( $self->{_dsn} =~ /;/ ) { |
649 |
my $dbh = DBI->connect($self->{_dsn}, $self->{_dbuser}, $self->{_dbpass}, |
650 |
## |
650 |
{'PrintError' => 0, 'AutoCommit' => 0}); |
651 |
## ok there's a semi-colon in there which means we're dealing |
651 |
|
652 |
## with multiple hosts |
652 |
if (!$dbh) { |
653 |
## |
|
|
654 |
my @multiple_dsns = split( /;/, $self->{_dsn}); |
655 |
dbg("bayes: Multiple DSNs provided.:".$self->{_dsn}); |
656 |
my $counter=0; |
657 |
for my $new_dsn (@multiple_dsns) { |
658 |
$counter++; |
659 |
$dbh = DBI->connect($new_dsn, $self->{_dbuser}, $self->{_dbpass}, |
660 |
{'PrintError' => 1, 'AutoCommit' => 0}); |
661 |
if (! $dbh) { |
662 |
dbg("bayes: ($counter) Couldn't connect to dsn:$new_dsn. Attempting another.".DBI->errstr()); |
663 |
} else { |
664 |
last; |
665 |
} |
666 |
} |
667 |
} else { |
668 |
dbg("bayes: Single DSN provided."); |
669 |
$dbh = DBI->connect($self->{_dsn}, $self->{_dbuser}, $self->{_dbpass}, |
670 |
{'PrintError' => 0, 'AutoCommit' => 0}); |
671 |
} |
672 |
## commented out because this is returning an error even though it is already connected. |
673 |
if (! $dbh) { |
653 |
dbg("bayes: unable to connect to database: ".DBI->errstr()); |
674 |
dbg("bayes: unable to connect to database: ".DBI->errstr()); |
654 |
return 0; |
675 |
return 0; |
655 |
} |
676 |
} else { |
656 |
else { |
|
|
657 |
dbg("bayes: database connection established"); |
677 |
dbg("bayes: database connection established"); |
658 |
} |
678 |
} |
659 |
|
679 |
|