Audio-DB
view release on metacpan or search on metacpan
DB/Adaptor/dbi/sqlite.pm view on Meta::CPAN
# my $dbh = $self->features_db or return;
# $dbh->do('UNLOCK TABLES') if $self->lock_on_load;
#
# foreach (keys %{$self->{load_stuff}{sth}}) {
# $self->{load_stuff}{sth}{$_}->finish;
# }
#
# my $counter = $self->{load_stuff}{counter};
# delete $self->{load_stuff};
# return $counter;
#}
=head2 dbh
Title : dbh
Usage : $db = $dbh->dbh
Function: get database handle
Returns : a DBI handle
Args : none
Status : Public
=cut
sub dbh { shift->{dbh} }
=head2 DESTROY
Title : DESTROY
Usage : $dbh->DESTROY
Function: disconnect database at destruct time
Returns : void
Args : none
Status : protected
This is the destructor for the class.
=cut
sub DESTROY {
my $self = shift;
$self->dbh->disconnect if defined $self->dbh;
}
=head2 debug
Title : debug
Usage : $dbh = $db->debug
Function: prints out debugging information
Returns : debugging information
Args : none
Status : Private
=cut
sub debug {
my $self = shift;
$self->dbh->debug(@_);
$self->SUPER::debug(@_);
}
##################
# QUERIES
##################
# Used to find out the id of the last value inserted
# for building databases...
sub lookup_counter {
my ($self,$field,$table) = @_;
my $dbh = $self->dbh;
my $sth = $dbh->prepare(qq{select $field from $table ORDER BY $field DESC LIMIT 1});
}
##sub prepare_count {
## my ($self,$type) = @_;
## my $dbh = $self->dbh;
## my $sth = $dbh->prepare(qq{select count(*) from $type});
## return $sth;
##}
#### NEW SUB
# This might come in handy later
# SOME OF THIS COULD BE MIGRATED OUT
# Generically fetch an item for a single table by its ID
# MIGRATE TO QUERY
# DEPRECATING
sub fetch_by_id {
my ($self,$class,$id) = @_;
my $dbh = $self->dbh;
my $table = $class;
$table =~ s/s$//;
my $sth = $dbh->prepare(qq{select * from $class where $class.$table\_id=?});
$sth->execute($id) or warn $sth->errstr;
my $h = $sth->fetchrow_hashref;
return $h;
}
## END NEW
# Fetch the sum of seconds or total file size
# UPDATED
sub query_for_total {
my ($self,$field) = @_;
my $dbh = $self->dbh;
my $sth = $dbh->prepare(qq{select sum($field) from songs});
$sth->execute();
my ($sum) = $sth->fetchrow_array;
return $sum;
}
# DEPRECATING
sub fetch_by_letter {
my ($self,$letter,$class) = @_;
my $dbh = $self->dbh;
my $sth = $dbh->prepare($queries{$class});
( run in 1.205 second using v1.01-cache-2.11-cpan-98e64b0badf )