X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debbugs%2FDB%2FUtil.pm;fp=Debbugs%2FDB%2FUtil.pm;h=0000000000000000000000000000000000000000;hb=1e6633a3780f4fd53fc4303852e84d13cdad2dc6;hp=d241f3343ee39b7f27f2e74f59943d65a84addb3;hpb=466f7faff129a5699c7674f59900a92aa256175d;p=debbugs.git diff --git a/Debbugs/DB/Util.pm b/Debbugs/DB/Util.pm deleted file mode 100644 index d241f33..0000000 --- a/Debbugs/DB/Util.pm +++ /dev/null @@ -1,96 +0,0 @@ -# This module is part of debbugs, and is released -# under the terms of the GPL version 2, or any later version. See the -# file README and COPYING for more information. -# Copyright 2017 by Don Armstrong . - -package Debbugs::DB::Util; - -=head1 NAME - -Debbugs::DB::Util -- Utility routines for the database - -=head1 SYNOPSIS - - -=head1 DESCRIPTION - - -=head1 BUGS - -None known. - -=cut - -use warnings; -use strict; -use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT); -use base qw(Exporter); - -BEGIN{ - ($VERSION) = q$Revision$ =~ /^Revision:\s+([^\s+])/; - $DEBUG = 0 unless defined $DEBUG; - - @EXPORT = (); - %EXPORT_TAGS = (select => [qw(select_one)], - execute => [qw(prepare_execute)] - ); - @EXPORT_OK = (); - Exporter::export_ok_tags(keys %EXPORT_TAGS); - $EXPORT_TAGS{all} = [@EXPORT_OK]; -} - -=head2 select - -Routines for select requests - -=over - -=item select_one - - select_one($dbh,$sql,@bind_vals) - -Returns the first column from the first row returned from a select statement - -=cut - -sub select_one { - my ($dbh,$sql,@bind_vals) = @_; - my $sth = $dbh-> - prepare_cached($sql, - {dbi_dummy => __FILE__.__LINE__ }) - or die "Unable to prepare statement: $sql"; - $sth->execute(@bind_vals) or - die "Unable to select one: ".$dbh->errstr(); - my $results = $sth->fetchall_arrayref([0]); - $sth->finish(); - return (ref($results) and ref($results->[0]))?$results->[0][0]:undef; -} - -=item prepare_execute - - prepare_execute($dbh,$sql,@bind_vals) - -Prepares and executes a statement - -=cut - -sub prepare_execute { - my ($dbh,$sql,@bind_vals) = @_; - my $sth = $dbh-> - prepare_cached($sql, - {dbi_dummy => __FILE__.__LINE__ }) - or die "Unable to prepare statement: $sql"; - $sth->execute(@bind_vals) or - die "Unable to execute statement: ".$dbh->errstr(); - $sth->finish(); -} - - -=back - -=cut - -1; - - -__END__