Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
ensembl-gh-mirror
ensembl
Commits
8c36d61c
Commit
8c36d61c
authored
May 08, 2006
by
Patrick Meidl
Browse files
added get_dbconnection()
parent
4403a9a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
2 deletions
+56
-2
modules/Bio/EnsEMBL/Utils/ConversionSupport.pm
modules/Bio/EnsEMBL/Utils/ConversionSupport.pm
+56
-2
No files found.
modules/Bio/EnsEMBL/Utils/ConversionSupport.pm
View file @
8c36d61c
...
...
@@ -52,6 +52,7 @@ use Bio::EnsEMBL::Utils::Exception qw(throw warning);
use
FindBin
qw($Bin $Script)
;
use
POSIX
qw(strftime)
;
use
Cwd
qw(abs_path)
;
use
DBI
;
=head2 new
...
...
@@ -139,7 +140,7 @@ sub parse_common_options {
$self
->
param
(
$name
,
$val
);
}
$self
->
param
('
conffile
',
$conffile
);
}
els
e
{
}
els
if
(
$conffile
)
{
warning
("
Unable to open configuration file
$conffile
for reading: $!
");
}
...
...
@@ -651,6 +652,59 @@ sub get_database {
return
$self
->
{'
_dba
'}
->
{
$database
};
}
=head2 get_dbconnection
Arg[1] : (optional) String $prefix - the prefix used for retrieving the
connection settings from the configuration
Example : my $dbh = $self->get_dbconnection;
Description : Connects to the database server specified. You don't have to
specify a database name (this is useful for running commands
like $dbh->do('show databases')).
Return type : DBI database handle
Exceptions : thrown if connection fails
Caller : general
Status : At Risk
=cut
sub
get_dbconnection
{
my
$self
=
shift
;
my
$prefix
=
shift
;
$self
->
check_required_params
(
"
${prefix}
host
",
"
${prefix}
port
",
"
${prefix}
user
",
);
my
$dsn
=
"
DBI:
"
.
(
$self
->
param
('
driver
')
||
'
mysql
')
.
"
:host=
"
.
$self
->
param
("
${prefix}
host
")
.
"
;port=
"
.
$self
->
param
("
${prefix}
port
");
if
(
$self
->
param
("
${prefix}
dbname
"))
{
$dsn
.=
"
;dbname=
"
.
$self
->
param
("
${prefix}
dbname
");
}
my
$dbh
;
eval
{
$dbh
=
DBI
->
connect
(
$dsn
,
$self
->
param
("
${prefix}
user
"),
$self
->
param
("
${prefix}
pass
"),
{'
RaiseError
'
=>
1
,
'
PrintError
'
=>
0
});
};
if
(
!
$dbh
||
$@
||
!
$dbh
->
ping
)
{
$self
->
log_error
("
Could not connect to db server as user
"
.
$self
->
param
("
${prefix}
user
")
.
"
using [
$dsn
] as a locator:
\n
"
.
$
DBI::
errstr
);
}
$self
->
{'
_dbh
'}
=
$dbh
;
return
$self
->
{'
_dbh
'};
}
=head2 get_glovar_database
Example : my $dba = $support->get_glovar_database;
...
...
@@ -1294,7 +1348,7 @@ sub init_log {
sub
finish_log
{
my
$self
=
shift
;
$self
->
log
("
All done.
"
.
$self
->
warnings
.
"
warnings.
");
$self
->
log
("
\n
All done.
"
.
$self
->
warnings
.
"
warnings.
");
if
(
$self
->
{'
_start_time
'})
{
$self
->
log
("
Runtime
");
my
$diff
=
time
-
$self
->
{'
_start_time
'};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment