X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDBUtils.pm;h=fd2873ebfe232a4090ff1ec0864df989dcf6c56c;hb=7783c24d2a5f3f7413dc18d5b96b8a98995ac7da;hp=a20c02661edb953461ed0b0ddaeb5c548d61174c;hpb=12451e347bef2bbcff8dec050255f01fe5a89a3c;p=kivitendo-erp.git diff --git a/SL/DBUtils.pm b/SL/DBUtils.pm index a20c02661..fd2873ebf 100644 --- a/SL/DBUtils.pm +++ b/SL/DBUtils.pm @@ -4,9 +4,10 @@ require Exporter; @ISA = qw(Exporter); @EXPORT = qw(conv_i conv_date conv_dateq do_query selectrow_query do_statement - dump_query quote_db_date selectall_hashref_query - selectfirst_hashref_query selectfirst_array_query - prepare_execute_query); + dump_query quote_db_date + selectfirst_hashref_query selectfirst_array_query + selectall_hashref_query selectall_array_query + prepare_execute_query prepare_query); sub conv_i { my ($value, $default) = @_; @@ -28,9 +29,11 @@ sub conv_dateq { } sub do_query { + $main::lxdebug->enter_sub(2); + my ($form, $dbh, $query) = splice(@_, 0, 3); - dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); + dump_query(LXDebug::QUERY, '', $query, @_); if (0 == scalar(@_)) { $dbh->do($query) || $form->dberror($query); @@ -38,14 +41,18 @@ sub do_query { $dbh->do($query, undef, @_) || $form->dberror($query . " (" . join(", ", @_) . ")"); } + + $main::lxdebug->leave_sub(2); } sub selectrow_query { &selectfirst_array_query } sub do_statement { + $main::lxdebug->enter_sub(2); + my ($form, $sth, $query) = splice(@_, 0, 3); - dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); + dump_query(LXDebug::QUERY, '', $query, @_); if (0 == scalar(@_)) { $sth->execute() || $form->dberror($query); @@ -53,6 +60,8 @@ sub do_statement { $sth->execute(@_) || $form->dberror($query . " (" . join(", ", @_) . ")"); } + + $main::lxdebug->leave_sub(2); } sub dump_query { @@ -82,10 +91,26 @@ sub quote_db_date { return "'$str'"; } +sub prepare_query { + $main::lxdebug->enter_sub(2); + + my ($form, $dbh, $query) = splice(@_, 0, 3); + + dump_query(LXDebug::QUERY, '', $query, @_); + + my $sth = $dbh->prepare($query) || $form->dberror($query); + + $main::lxdebug->leave_sub(2); + + return $sth; +} + sub prepare_execute_query { + $main::lxdebug->enter_sub(2); + my ($form, $dbh, $query) = splice(@_, 0, 3); - dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); + dump_query(LXDebug::QUERY, '', $query, @_); my $sth = $dbh->prepare($query) || $form->dberror($query); if (scalar(@_) != 0) { @@ -94,13 +119,15 @@ sub prepare_execute_query { $sth->execute() || $form->dberror($query); } + $main::lxdebug->leave_sub(2); + return $sth; } sub selectall_hashref_query { - my ($form, $dbh, $query) = splice(@_, 0, 3); + $main::lxdebug->enter_sub(2); - dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); + my ($form, $dbh, $query) = splice(@_, 0, 3); my $sth = prepare_execute_query($form, $dbh, $query, @_); my $result = []; @@ -109,30 +136,53 @@ sub selectall_hashref_query { } $sth->finish(); + $main::lxdebug->leave_sub(2); + return $result; } -sub selectfirst_hashref_query { +sub selectall_array_query { + $main::lxdebug->enter_sub(2); + 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 ($value) = $sth->fetchrow_array()) { + push(@result, $value); + } + $sth->finish(); + + $main::lxdebug->leave_sub(2); + + return @result; +} + +sub selectfirst_hashref_query { + $main::lxdebug->enter_sub(2); + + my ($form, $dbh, $query) = splice(@_, 0, 3); my $sth = prepare_execute_query($form, $dbh, $query, @_); my $ref = $sth->fetchrow_hashref(); $sth->finish(); + $main::lxdebug->leave_sub(2); + return $ref; } sub selectfirst_array_query { - my ($form, $dbh, $query) = splice(@_, 0, 3); + $main::lxdebug->enter_sub(2); - dump_query(LXDebug::QUERY, '', $query . " (" . join(", ", @_) . ")", @_); + my ($form, $dbh, $query) = splice(@_, 0, 3); my $sth = prepare_execute_query($form, $dbh, $query, @_); my @ret = $sth->fetchrow_array(); $sth->finish(); + $main::lxdebug->leave_sub(2); + return @ret; } @@ -205,7 +255,8 @@ SL::DBUTils.pm: All about Databaseconections in Lx =head1 MODULE AUTHORS -Sven Schoeling +Moritz Bunkus Em.bunkus@linet-services.de +Sven Schoeling Es.schoeling@linet-services.de =head1 DOCUMENTATION AUTHORS @@ -227,4 +278,4 @@ 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 +=cut