Skip to content
Snippets Groups Projects
Commit 38a39820 authored by Leo Gordon's avatar Leo Gordon
Browse files

sqlite engine support added for eHive

parent 8b713994
No related branches found
No related tags found
No related merge requests found
......@@ -355,6 +355,7 @@ sub store {
throw("Analysis cannot be stored without a valid logic_name");
}
my $insertion_method = (lc($self->dbc->driver) eq 'sqlite') ? 'INSERT OR IGNORE' : 'INSERT IGNORE';
my $rows_inserted = 0;
my $sth;
......@@ -366,21 +367,10 @@ sub store {
# this record then there will not be a problem.
$sth = $self->prepare(
q{
INSERT IGNORE INTO analysis
SET created = ?,
logic_name = ?,
db = ?,
db_version = ?,
db_file = ?,
program = ?,
program_version = ?,
program_file = ?,
parameters = ?,
module = ?,
module_version = ?,
gff_source = ?,
gff_feature = ?
qq{
$insertion_method INTO analysis
(created, logic_name, db, db_version, db_file, program, program_version, program_file, parameters, module, module_version, gff_source, gff_feature)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
}
);
$sth->bind_param( 1, $analysis->created(), SQL_DATETIME );
......@@ -401,22 +391,11 @@ sub store {
} else {
$sth = $self->prepare(
q{
INSERT IGNORE INTO analysis
SET created = now(),
logic_name = ?,
db = ?,
db_version = ?,
db_file = ?,
program = ?,
program_version = ?,
program_file = ?,
parameters = ?,
module = ?,
module_version = ?,
gff_source = ?,
gff_feature = ?
}
qq{
$insertion_method INTO analysis
(created, logic_name, db, db_version, db_file, program, program_version, program_file, parameters, module, module_version, gff_source, gff_feature)
VALUES (CURRENT_TIMESTAMP, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
}
);
$sth->bind_param( 1, $analysis->logic_name, SQL_VARCHAR );
......
......@@ -149,42 +149,43 @@ sub new {
throw("Cannot specify other arguments when -DBCONN argument used.");
}
$self->dbname($dbconn->dbname());
$self->username($dbconn->username());
$self->driver($dbconn->driver());
$self->host($dbconn->host());
$self->password($dbconn->password());
$self->port($dbconn->port());
$self->driver($dbconn->driver());
$self->username($dbconn->username());
$self->password($dbconn->password());
$self->dbname($dbconn->dbname());
if($dbconn->disconnect_when_inactive()) {
$self->disconnect_when_inactive(1);
}
} else {
$db || throw("-DBNAME argument is required.");
$user || throw("-USER argument is required.");
$db || throw("-DBNAME argument is required.");
$driver ||= 'mysql';
$host ||= 'mysql';
if(!defined($port)){
$port = 3306;
if($host eq "ensembldb.ensembl.org"){
if( $db =~ /\w+_\w+_\w+_(\d+)/){
if($1 >= 48){
$port = 5306;
}
}
}
if($driver eq 'mysql') {
$user || throw("-USER argument is required.");
$host ||= 'mysql';
if(!defined($port)){
$port = 3306;
if($host eq "ensembldb.ensembl.org"){
if( $db =~ /\w+_\w+_\w+_(\d+)/){
if($1 >= 48){
$port = 5306;
}
}
}
}
}
$wait_timeout ||= 0;
$self->username( $user );
$self->driver($driver);
$self->host( $host );
$self->dbname( $db );
$self->password( $password );
$self->port($port);
$self->driver($driver);
$self->username( $user );
$self->password( $password );
$self->dbname( $db );
$self->timeout($wait_timeout);
if($inactive_disconnect) {
......@@ -272,6 +273,20 @@ sub connect {
} );
};
} elsif ( lc($self->driver()) eq 'sqlite' ) {
$dsn = sprintf( "DBI:SQLite:%s", $self->dbname() );
eval {
$dbh = DBI->connect(
$dsn,
'',
'',
{
'RaiseError' => 1,
} );
};
} else {
$dsn = sprintf(
......@@ -642,7 +657,7 @@ sub prepare {
throw("Attempting to prepare an empty SQL query.");
}
# print STDERR "SQL(".$self->dbname."):" . join(' ', @args) . "\n";
#warn "SQL(".$self->dbname."):" . join(' ', @args) . "\n";
my $sth = $self->db_handle->prepare(@args);
......@@ -678,7 +693,7 @@ sub do {
throw("Attempting to do an empty SQL query.");
}
#info("SQL(".$self->dbname."):$string");
# warn "SQL(".$self->dbname."): $string";
my $result = $self->db_handle->do($string);
......@@ -771,16 +786,16 @@ sub add_limit_clause{
my $new_sql = '';
if ($self->driver eq 'mysql'){
$new_sql = $sql . ' LIMIT ' . $max_number;
$new_sql = $sql . ' LIMIT ' . $max_number;
}
elsif ($self->driver eq 'odbc'){
#need to get anything after the SELECT statement
$sql =~ /select(.*)/i;
$new_sql = 'SELECT TOP ' . $max_number . $1;
#need to get anything after the SELECT statement
$sql =~ /select(.*)/i;
$new_sql = 'SELECT TOP ' . $max_number . $1;
}
else{
warning("Not possible to convert $sql to an unknow database driver: ", $self->driver, " no limit applied");
$new_sql = $sql;
warning("Not possible to convert $sql to an unknow database driver: ", $self->driver, " no limit applied");
$new_sql = $sql;
}
return $new_sql;
}
......@@ -805,14 +820,14 @@ sub from_date_to_seconds{
my $string;
if ($self->driver eq 'mysql'){
$string = "UNIX_TIMESTAMP($column)";
$string = "UNIX_TIMESTAMP($column)";
}
elsif ($self->driver eq 'odbc'){
$string = "DATEDIFF(second,'JAN 1 1970',$column)";
$string = "DATEDIFF(second,'JAN 1 1970',$column)";
}
else{
warning("Not possible to convert $column due to an unknown database driver: ", $self->driver);
return '';
warning("Not possible to convert $column due to an unknown database driver: ", $self->driver);
return '';
}
return $string;
}
......@@ -837,24 +852,24 @@ sub from_seconds_to_date{
my $string;
if ($self->driver eq 'mysql'){
if ($seconds){
$string = "from_unixtime( ".$seconds.")";
}
else{
$string = "\"0000-00-00 00:00:00\"";
}
if ($seconds){
$string = "from_unixtime( ".$seconds.")";
}
else{
$string = "\"0000-00-00 00:00:00\"";
}
}
elsif ($self->driver eq 'odbc'){
if ($seconds){
$string = "DATEDIFF(date,'JAN 1 1970',$seconds)";
}
else{
$string = "\"0000-00-00 00:00:00\"";
}
if ($seconds){
$string = "DATEDIFF(date,'JAN 1 1970',$seconds)";
}
else{
$string = "\"0000-00-00 00:00:00\"";
}
}
else{
warning("Not possible to convert $seconds due to an unknown database driver: ", $self->driver);
return '';
warning("Not possible to convert $seconds due to an unknown database driver: ", $self->driver);
return '';
}
return $string;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment