From 9d047497dcea5258e2fab7eb2cbe8606a74f27e0 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 20 Mar 2007 14:42:02 +0000 Subject: [PATCH] Mehr Datenbankhilfsfunktionen implementiert. --- SL/DBUtils.pm | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/SL/DBUtils.pm b/SL/DBUtils.pm index 78a381775..7a0b9cf48 100644 --- a/SL/DBUtils.pm +++ b/SL/DBUtils.pm @@ -3,7 +3,9 @@ package SL::DBUtils; require Exporter; @ISA = qw(Exporter); -@EXPORT = qw(conv_i conv_date conv_dateq do_query selectrow_query do_statement dump_query quote_db_date); +@EXPORT = qw(conv_i conv_date conv_dateq do_query selectrow_query do_statement + dump_query quote_db_date selectall_hashref_query + prepare_execute_query); sub conv_i { my ($value, $default) = @_; @@ -83,4 +85,30 @@ sub quote_db_date { return "'$str'"; } +sub prepare_execute_query { + my ($form, $dbh, $query) = splice(@_, 0, 3); + my $sth = $dbh->prepare($query) || $form->dberror($query); + if (scalar(@_) != 0) { + $sth->execute(@_) || $form->dberror($query . " (" . join(", ", @_) . ")"); + } else { + $sth->execute() || $form->dberror($query); + } + + return $sth; +} + +sub selectall_hashref_query { + my ($form, $dbh, $query) = splice(@_, 0, 3); + + my $sth = prepare_execute_query($form, $dbh, $query, @_); + my $result = []; + while (my $ref = $sth->fetchrow_hashref()) { + push(@{ $result }, $ref); + } + $sth->finish(); + + return $result; +} + + 1; -- 2.20.1