mysql.pm 2.6 KB
Newer Older
1 2
=head1 LICENSE

Magali Ruffier's avatar
Magali Ruffier committed
3
Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
premanand17's avatar
premanand17 committed
4
Copyright [2016-2018] EMBL-European Bioinformatics Institute
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut

package Bio::EnsEMBL::Test::MultiTestDB::mysql;

=pod

=head1 NAME

Bio::EnsEMBL::Test::MultiTestDB::mysql

=head1 DESCRIPTION

MySQL specifics for Bio::EnsEMBL::Test::MultiTestDB.

Used automatically, as determined by the 'driver' setting in MultiTestDB.conf.

=cut

use strict;
use warnings;

use English qw(-no_match_vars);

use base 'Bio::EnsEMBL::Test::MultiTestDB';

sub load_txt_dump {
    my ($self, $txt_file, $tablename, $db) = @_;
    my $load = sprintf(q{LOAD DATA LOCAL INFILE '%s' INTO TABLE `%s` FIELDS ESCAPED BY '\\\\'}, $txt_file, $tablename);
    $db->do($load);
47
    return $db;
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
}

sub create_and_use_db {
    my ($self, $db, $dbname) = @_;
    my $create_db = $db->do("CREATE DATABASE $dbname");
    if(! $create_db) {
      $self->note("!! Could not create database [$dbname]");
      return;
    }

    $db->do('use '.$dbname);
    return $db;
}

sub _db_conf_to_dbi {
  my ($self, $db_conf, $options) = @_;
  my %params = (host => $db_conf->{host}, port => $db_conf->{port});
  %params = (%params, %{$options}) if $options;
  my $param_str = join(q{;}, map { $_.'='.$params{$_} } keys %params);
  my $locator = sprintf('DBI:%s:%s', $db_conf->{driver}, $param_str);
  my $db = DBI->connect( $locator, $db_conf->{user}, $db_conf->{pass}, { RaiseError => 1 } );
  return $db if $db;
  $self->diag("Can't connect to database '$locator': ". $DBI::errstr);
  return;
}

sub _dbi_options {
    my $self = shift;
    return {mysql_local_infile => 1};
}

sub _schema_name {
    my ($self, $dbname) = @_;
    return $dbname;
}

sub _db_path {
    my ($self, $driver_handle) = @_;
    return;
}

sub _drop_database {
    my ($self, $db, $dbname) = @_;

    eval {$db->do("DROP DATABASE $dbname");};
    $self->diag("Could not drop database $dbname: $EVAL_ERROR") if $EVAL_ERROR;

    $db->disconnect();

    return;
}

sub do_disconnect {
    my ($self) = @_;
    my $db = $self->dbi_connection();
    $db->disconnect;
    return;
}

1;