From: Moritz Bunkus Date: Tue, 7 Nov 2006 11:02:45 +0000 (+0000) Subject: Komfort- und Hilfsfunktionen fuer den Datenbankzugriff. X-Git-Tag: release-2.4.0^2~244 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=e7530c83690d28dd9b1633c2e06062a092d9c8c9;p=kivitendo-erp.git Komfort- und Hilfsfunktionen fuer den Datenbankzugriff. --- 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;