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
27 use base qw(DBIx::Class);
29 use Debbugs::Common qw(open_compressed_file);
33 Routines for select requests
39 $schema->select_one($sql,@bind_vals)
41 Returns the first column from the first row returned from a select statement
46 my ($self,$sql,@bind_vals) = @_;
53 {dbi_dummy => __FILE__.__LINE__ })
54 or die "Unable to prepare statement: $sql";
55 $sth->execute(@bind_vals) or
56 die "Unable to select one: ".$dbh->errstr();
57 my $results = $sth->fetchall_arrayref([0]);
61 return (ref($results) and ref($results->[0]))?$results->[0][0]:undef;
66 $schema->prepare_execute($sql,@bind_vals)
68 Prepares and executes a statement
73 my ($self,$sql,@bind_vals) = @_;
79 {dbi_dummy => __FILE__.__LINE__ })
80 or die "Unable to prepare statement: $sql";
81 $sth->execute(@bind_vals) or
82 die "Unable to execute statement: ".$dbh->errstr();
96 my $fh = open_compressed_file($fn) or
97 die "Unable to open $fn for reading: $!";
100 defined($sql) or die "Unable to read from file: $!";
101 $self->prepare_execute($sql);