From e7530c83690d28dd9b1633c2e06062a092d9c8c9 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 7 Nov 2006 11:02:45 +0000 Subject: [PATCH] Komfort- und Hilfsfunktionen fuer den Datenbankzugriff. --- SL/DBUtils.pm | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 SL/DBUtils.pm diff --git a/SL/DBUtils.pm b/SL/DBUtils.pm new file mode 100644 index 000000000..05837b577 --- /dev/null +++ b/SL/DBUtils.pm @@ -0,0 +1,43 @@ +package SL::DBUtils; + +require Exporter; +@ISA = qw(Exporter); + +@EXPORT = qw(conv_i conv_date do_query dump_query); + +sub conv_i { + my ($value, $default) = @_; + return (defined($value) && "$value" ne "") ? $value * 1 : $default; +} + +sub conv_date { + my ($value) = @_; + return (defined($value) && "$value" ne "") ? $value : undef; +} + +sub do_query { + my ($form, $dbh, $query) = splice(@_, 0, 3); + + if (0 == scalar(@_)) { + $dbh->do($query) || $form->dberror($query); + } else { + $dbh->do($query, undef, @_) || + $form->dberror($query . " (" . join(", ", @_) . ")"); + } +} + +sub dump_query { + my ($level, $msg, $query) = splice(@_, 0, 3); + while ($query =~ /\?/) { + my $value = shift(@_); + $value =~ s/\'/\\\'/g; + $value = "'${value}'"; + $query =~ s/\?/$value/; + } + + $msg .= " " if ($msg); + + $main::lxdebug->message($level, $msg . $query); +} + +1; -- 2.20.1