aboutsummaryrefslogtreecommitdiffstats
path: root/lib/SpamCat.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/SpamCat.pm')
-rw-r--r--lib/SpamCat.pm29
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/SpamCat.pm b/lib/SpamCat.pm
index 5c6db51..d470520 100644
--- a/lib/SpamCat.pm
+++ b/lib/SpamCat.pm
@@ -75,6 +75,12 @@ sub parse_to {
} @tovals;
}
+sub get_table {
+ my ($self) = @_;
+
+ $self->in_transaction(sub { $self->get_table_t() });
+}
+
sub get_count {
my ($self, $sender) = @_;
@@ -97,6 +103,26 @@ sub decrement_count {
# The _t functions are meant to be run inside transacitons.
#
+sub get_table_t {
+ my ($self) = @_;
+
+ my @rows;
+ my $q = 'SELECT * FROM emails';
+ my $sth = $self->{dbh}->prepare($q);
+ $sth->execute();
+ while (my $row = $sth->fetchrow_hashref) {
+ push @rows, $row
+ }
+ if ($sth->err) {
+ $sth->finish;
+ carp $sth->errstr;
+ return;
+ }
+ $sth->finish;
+
+ \@rows;
+}
+
sub get_count_t {
my ($self, $sender) = @_;
@@ -154,8 +180,7 @@ sub in_transaction {
my $rc = eval { &$sub($self); };
if ($@) {
$self->{dbh}->rollback;
- warn "ERROR: Transaction failed: $@\n";
- exit 1;
+ carp "Transaction failed: $@\n";
} else {
$self->{dbh}->commit;
}