X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDBUtils.pm;h=d638f895746b6f4001032a2d2530249b460e69ae;hb=ecdc6333a9267d71db73e82fac1c29d8c7d0e394;hp=c9c70c95a94fabd69881b6d8c79465925ff75af3;hpb=be54aea5115bbfcc5d91de846879126417cacdbd;p=kivitendo-erp.git diff --git a/SL/DBUtils.pm b/SL/DBUtils.pm index c9c70c95a..d638f8957 100644 --- a/SL/DBUtils.pm +++ b/SL/DBUtils.pm @@ -8,7 +8,7 @@ our @ISA = qw(Exporter); our @EXPORT = qw(conv_i conv_date conv_dateq do_query selectrow_query do_statement dump_query quote_db_date like selectfirst_hashref_query selectfirst_array_query - selectall_hashref_query selectall_array_query + selectall_hashref_query selectall_array_query selectcol_array_query selectall_as_map selectall_ids prepare_execute_query prepare_query @@ -171,16 +171,15 @@ sub selectall_hashref_query { return wantarray ? @{ $result } : $result; } -sub selectall_array_query { +sub selectall_array_query { goto &selectcol_array_query; } + +sub selectcol_array_query { $main::lxdebug->enter_sub(2); my ($form, $dbh, $query) = splice(@_, 0, 3); my $sth = prepare_execute_query($form, $dbh, $query, @_); - my @result; - while (my ($value) = $sth->fetchrow_array()) { - push(@result, $value); - } + my @result = @{ $dbh->selectcol_arrayref($sth) }; $sth->finish(); $main::lxdebug->leave_sub(2); @@ -408,7 +407,7 @@ __END__ =head1 NAME -SL::DBUTils.pm: All about database connections in kivitendo +SL::DBUtils.pm: All about database connections in kivitendo =head1 SYNOPSIS @@ -419,6 +418,8 @@ SL::DBUTils.pm: All about database connections in kivitendo conv_dateq($str) quote_db_date($date) + my $dbh = SL::DB->client->dbh; + do_query($form, $dbh, $query) do_statement($form, $sth, $query) @@ -428,9 +429,11 @@ SL::DBUTils.pm: All about database connections in kivitendo 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 = selectfirst_array_query($form, $dbh, $query); my @first_result = selectrow_query($form, $dbh, $query); + my @values = selectcol_array_query($form, $dbh, $query); + my %sort_spec = create_sort_spec(%params); =head1 DESCRIPTION @@ -439,7 +442,7 @@ DBUtils provides wrapper functions for low level database retrieval. It saves you the trouble of mucking around with statement handles for small database queries and does exception handling in the common cases for you. -Query and retrieval function share the parameter scheme: +Query and retrieval functions share the parameter scheme: query_or_retrieval(C