1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later version. See the
3 # file README and COPYING for more information.
4 # Copyright 2017 by Don Armstrong <don@donarmstrong.com>.
6 package Debbugs::DB::Util;
10 Debbugs::DB::Util -- Utility routines for the database
26 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
27 use base qw(Exporter);
30 ($VERSION) = q$Revision$ =~ /^Revision:\s+([^\s+])/;
31 $DEBUG = 0 unless defined $DEBUG;
34 %EXPORT_TAGS = (select => [qw(select_one)],
37 Exporter::export_ok_tags(keys %EXPORT_TAGS);
38 $EXPORT_TAGS{all} = [@EXPORT_OK];
43 Routines for select requests
49 select_one($dbh,$sql,@bind_vals)
51 Returns the first column from the first row returned from a select statement
56 my ($dbh,$sql,@bind_vals) = @_;
59 {dbi_dummy => __FILE__.__LINE__ })
60 or die "Unable to prepare statement: $sql";
61 $sth->execute(@bind_vals) or
62 die "Unable to select one: ".$dbh->errstr();
63 my $results = $sth->fetchall_arrayref([0]);
65 return (ref($results) and ref($results->[0]))?$results->[0][0]:undef;