From 12451e347bef2bbcff8dec050255f01fe5a89a3c Mon Sep 17 00:00:00 2001 From: Udo Spallek Date: Wed, 28 Mar 2007 02:29:51 +0000 Subject: [PATCH] =?utf8?q?SL::DBUtils=20etwas=20verbessert.=20Bei=20jedem?= =?utf8?q?=20Query=20wird=20gepr=C3=BCft=20ob=20der=20Debugmodus=20eingesc?= =?utf8?q?haltet=20ist->=20Eintrag=20ins=20Log.=20Auch=20habe=20ich=20eine?= =?utf8?q?=20Anleitung=20f=C3=BCr=20das=20Modul=20angefangen,=20aber=20bis?= =?utf8?q?her=20nur=20den=20Aufruf=20einiger=20Funktionen=20beschrieben=20?= =?utf8?q?siehe=20perldoc=20SL/DBUtils.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DBUtils.pm | 108 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/SL/DBUtils.pm b/SL/DBUtils.pm index a4441027f..a20c02661 100644 --- a/SL/DBUtils.pm +++ b/SL/DBUtils.pm @@ -29,7 +29,9 @@ sub conv_dateq { sub do_query { my ($form, $dbh, $query) = splice(@_, 0, 3); + dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); + if (0 == scalar(@_)) { $dbh->do($query) || $form->dberror($query); } else { @@ -43,6 +45,8 @@ sub selectrow_query { &selectfirst_array_query } sub do_statement { my ($form, $sth, $query) = splice(@_, 0, 3); + dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); + if (0 == scalar(@_)) { $sth->execute() || $form->dberror($query); } else { @@ -53,6 +57,7 @@ sub do_statement { sub dump_query { my ($level, $msg, $query) = splice(@_, 0, 3); + while ($query =~ /\?/) { my $value = shift(@_); $value =~ s/\'/\\\'/g; @@ -69,16 +74,20 @@ sub dump_query { sub quote_db_date { my ($str) = @_; + return "NULL" unless defined $str; return "current_date" if $str =~ /current_date/; + $str =~ s/'/''/g; return "'$str'"; } sub prepare_execute_query { my ($form, $dbh, $query) = splice(@_, 0, 3); - my $sth = $dbh->prepare($query) || $form->dberror($query); + dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); + + my $sth = $dbh->prepare($query) || $form->dberror($query); if (scalar(@_) != 0) { $sth->execute(@_) || $form->dberror($query . " (" . join(", ", @_) . ")"); } else { @@ -91,6 +100,8 @@ sub prepare_execute_query { sub selectall_hashref_query { my ($form, $dbh, $query) = splice(@_, 0, 3); + dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); + my $sth = prepare_execute_query($form, $dbh, $query, @_); my $result = []; while (my $ref = $sth->fetchrow_hashref()) { @@ -104,6 +115,8 @@ sub selectall_hashref_query { sub selectfirst_hashref_query { my ($form, $dbh, $query) = splice(@_, 0, 3); + dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); + my $sth = prepare_execute_query($form, $dbh, $query, @_); my $ref = $sth->fetchrow_hashref(); $sth->finish(); @@ -114,6 +127,8 @@ sub selectfirst_hashref_query { sub selectfirst_array_query { my ($form, $dbh, $query) = splice(@_, 0, 3); + dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); + my $sth = prepare_execute_query($form, $dbh, $query, @_); my @ret = $sth->fetchrow_array(); $sth->finish(); @@ -122,3 +137,94 @@ sub selectfirst_array_query { } 1; + + +__END__ + +=head1 NAME + +SL::DBUTils.pm: All about Databaseconections in Lx + +=head1 SYNOPSIS + + use DBUtils; + + conv_i + conv_date + conv_dateq + quote_db_date($str) + + do_query($form, $dbh, $query) + do_statement($form, $sth, $query) + + dump_query($level, $msg, $query) + prepare_execute_query($form, $dbh, $query) + + my $all_results_ref = selectall_hashref_query($form, $dbh, $query) + my $first_result_hash_ref = selectfirst_hashref_query($form, $dbh, $query); + + my @first_result = selectfirst_array_query($form, $dbh, $query); # == + my @first_result = selectrow_query($form, $dbh, $query); + + +=head1 DESCRIPTION + +=head1 FUNCTIONS + +=over 4 + +=item conv_i + +=item conv_date + +=item conv_dateq + +=item quote_db_date($str) + +=item do_query($form, $dbh, $query) + +=item do_statement($form, $sth, $query) + +=item dump_query($level, $msg, $query) + +=item prepare_execute_query($form, $dbh, $query) + +=item selectall_hashref_query($form, $dbh, $query) + +=item selectfirst_hashref_query($form, $dbh, $query); + +=item selectfirst_array_query($form, $dbh, $query); # == + +=item selectrow_query($form, $dbh, $query); + +=back + +=head1 EXAMPLE + +=head1 SEE ALSO + +=head1 MODULE AUTHORS + +Sven Schoeling + +=head1 DOCUMENTATION AUTHORS + +Udo Spallek Eudono@gmx.netE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2007 by Lx-Office Community + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +=cut \ No newline at end of file -- 2.20.1