Skip to content
Snippets Groups Projects
Commit 658a243d authored by Michael Gray's avatar Michael Gray
Browse files

rows() doesn't work on SQLite for SELECT unless all rows actually fetched!

[Adaptors]
parent f7c005e8
No related branches found
No related tags found
3 merge requests!2SQLite support / database portability for EnsEMBL,!2SQLite support / database portability for EnsEMBL,!2SQLite support / database portability for EnsEMBL
......@@ -494,12 +494,16 @@ sub _seq_region_name_to_id {
$sth->bind_param(2,$cs_id,SQL_INTEGER);
$sth->execute();
if(!$sth->rows() == 1) {
throw("Ambiguous or non-existant seq_region [$sr_name] " .
"in coord system $cs_id");
my @row = $sth->fetchrow_array();
unless ( @row ) {
throw("No-existent seq_region [$sr_name] in coord system $cs_id");
}
my @more = $sth->fetchrow_array();
if ( @more ) {
throw("Ambiguous seq_region [$sr_name] in coord system $cs_id");
}
my ($sr_id, $sr_length) = $sth->fetchrow_array();
my ($sr_id, $sr_length) = @row;
$sth->finish();
$arr = [ $sr_id, $sr_name, $cs_id, $sr_length ];
......@@ -532,11 +536,12 @@ sub _seq_region_id_to_name {
$sth->bind_param(1,$sr_id,SQL_INTEGER);
$sth->execute();
my @row = $sth->fetchrow_array();
if(!$sth->rows() == 1) {
throw("non-existant seq_region [$sr_id]");
}
my ($sr_name, $sr_length, $cs_id) = $sth->fetchrow_array();
my ($sr_name, $sr_length, $cs_id) = @row;
$sth->finish();
$arr = [ $sr_id, $sr_name, $cs_id, $sr_length ];
......@@ -615,6 +620,8 @@ sub register_component {
$sth->bind_param(2,$asm_cs_id,SQL_INTEGER);
$sth->execute();
my @rows = $sth->fetchrow_array();
if($sth->rows() == 0) {
#this component is not used in the assembled part i.e. gap
$asm_mapper->register_component($cmp_seq_region);
......@@ -627,6 +634,7 @@ sub register_component {
# chromosome:EquCab2#contig ( use'#' for multiple mappings )
# chromosome:EquCab2|contig ( use '|' delimiter for 1-1 mappings )
#
my @more = $sth->fetchrow_array();
if($sth->rows() != 1) {
$sth->finish();
throw("Multiple assembled regions for single " .
......@@ -636,7 +644,7 @@ sub register_component {
}
my ($asm_start, $asm_end, $asm_seq_region_id,
$asm_seq_region, $asm_seq_region_length) = $sth->fetchrow_array();
$asm_seq_region, $asm_seq_region_length) = @rows;
my $arr = [ $asm_seq_region_id, $asm_seq_region,
$asm_cs_id, $asm_seq_region_length ];
......
......@@ -260,12 +260,12 @@ sub store {
$sth2->bind_param(1,$ms->code,SQL_VARCHAR);
$sth2->execute();
($dbID) = $sth2->fetchrow_array();
if($sth2->rows() != 1) {
throw("Could not retrieve or store MiscSet, code=[".$ms->code."]\n".
"Wrong database user/permissions?");
}
($dbID) = $sth2->fetchrow_array();
} else {
$dbID = $sth->{'mysql_insertid'};
}
......
......@@ -150,14 +150,15 @@ sub fetch_by_dbID {
$sth->bind_param(1, $protfeat_id, SQL_INTEGER);
my $res = $sth->execute();
my ($start, $end, $analysis_id, $score, $perc_ident, $pvalue, $hstart,
$hend, $hseqname, $idesc, $interpro_ac) = $sth->fetchrow_array();
if ($sth->rows == 0) {
$sth->finish();
return undef;
if($sth->rows == 0) {
$sth->finish();
return undef;
}
my ($start, $end, $analysis_id, $score, $perc_ident, $pvalue, $hstart, $hend, $hseqname, $idesc, $interpro_ac) = $sth->fetchrow_array();
$sth->finish();
my $analysis = $self->db->get_AnalysisAdaptor->fetch_by_dbID($analysis_id);
......
......@@ -299,10 +299,10 @@ sub fetch_by_region {
}
$sth->execute();
my @row = $sth->fetchrow_array();
$sth->finish();
if ( $sth->rows() == 0 ) {
$sth->finish();
unless ( @row ) {
# try synonyms
my $syn_sql_sth = $self->prepare("select s.name, cs.name, cs.version from seq_region s join seq_region_synonym ss using (seq_region_id) join coord_system cs using (coord_system_id) where ss.synonym = ? and cs.species_id =?");
......@@ -407,9 +407,7 @@ sub fetch_by_region {
} else {
my ( $id, $cs_id );
( $seq_region_name, $id, $length, $cs_id ) =
$sth->fetchrow_array();
$sth->finish();
( $seq_region_name, $id, $length, $cs_id ) = @row;
# cache to speed up for future queries
my $arr = [ $id, $seq_region_name, $cs_id, $length ];
......@@ -832,7 +830,8 @@ sub fetch_by_seq_region_id {
$sth->bind_param( 1, $seq_region_id, SQL_INTEGER );
$sth->execute();
if ( $sth->rows() == 0 ) {
my @row = $sth->fetchrow_array();
unless ( @row ) {
# This could have been an old seq region id so see if we can
# translate it into a more recent version.
if($check_prior_ids) {
......@@ -845,7 +844,7 @@ sub fetch_by_seq_region_id {
return undef;
}
( $name, $cs_id, $length ) = $sth->fetchrow_array();
( $name, $cs_id, $length ) = @row;
$sth->finish();
$cs = $self->db->get_CoordSystemAdaptor->fetch_by_dbID($cs_id);
......@@ -914,14 +913,16 @@ sub get_seq_region_id {
$sth->bind_param(2,$cs_id,SQL_INTEGER);
$sth->execute();
if($sth->rows() != 1) {
throw("Non existant or ambigous seq_region:\n" .
" coord_system=[$cs_id],\n" .
" name=[$seq_region_name],\n");
my @row = $sth->fetchrow_array();
unless ( @row ) {
throw("No-existent seq_region [$seq_region_name] in coord system [$cs_id]");
}
my @more = $sth->fetchrow_array();
if ( @more ) {
throw("Ambiguous seq_region [$seq_region_name] in coord system [$cs_id]");
}
my($seq_region_id, $length) = $sth->fetchrow_array();
my($seq_region_id, $length) = @row;
$sth->finish();
#cache information for future requests
......@@ -2618,13 +2619,13 @@ sub fetch_by_clone_accession{
$sth->bind_param( 1, $self->species_id(), SQL_INTEGER );
$sth->execute();
($name) = $sth->fetchrow_array();
if(!$sth->rows()) {
$sth->finish();
throw("Clone $name not found in database");
}
($name) = $sth->fetchrow_array();
$sth->finish();
}
......
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