Revision 4b29b4b6
Von G. Richardson vor mehr als 5 Jahren hinzugefügt
SL/DBUtils.pm | ||
---|---|---|
8 | 8 |
our @EXPORT = qw(conv_i conv_date conv_dateq do_query selectrow_query do_statement |
9 | 9 |
dump_query quote_db_date like |
10 | 10 |
selectfirst_hashref_query selectfirst_array_query |
11 |
selectall_hashref_query selectall_array_query |
|
11 |
selectall_hashref_query selectall_array_query selectcol_array_query
|
|
12 | 12 |
selectall_as_map |
13 | 13 |
selectall_ids |
14 | 14 |
prepare_execute_query prepare_query |
... | ... | |
171 | 171 |
return wantarray ? @{ $result } : $result; |
172 | 172 |
} |
173 | 173 |
|
174 |
sub selectall_array_query { |
|
174 |
sub selectall_array_query { goto &selectcol_array_query; } |
|
175 |
|
|
176 |
sub selectcol_array_query { |
|
175 | 177 |
$main::lxdebug->enter_sub(2); |
176 | 178 |
|
177 | 179 |
my ($form, $dbh, $query) = splice(@_, 0, 3); |
178 | 180 |
|
179 | 181 |
my $sth = prepare_execute_query($form, $dbh, $query, @_); |
180 |
my @result; |
|
181 |
while (my ($value) = $sth->fetchrow_array()) { |
|
182 |
push(@result, $value); |
|
183 |
} |
|
182 |
my @result = @{ $dbh->selectcol_arrayref($sth) }; |
|
184 | 183 |
$sth->finish(); |
185 | 184 |
|
186 | 185 |
$main::lxdebug->leave_sub(2); |
... | ... | |
433 | 432 |
my @first_result = selectfirst_array_query($form, $dbh, $query); |
434 | 433 |
my @first_result = selectrow_query($form, $dbh, $query); |
435 | 434 |
|
435 |
my @values = selectcol_array_query($form, $dbh, $query); |
|
436 |
|
|
436 | 437 |
my %sort_spec = create_sort_spec(%params); |
437 | 438 |
|
438 | 439 |
=head1 DESCRIPTION |
... | ... | |
615 | 616 |
the data structure will actually be a reference to an array, containing |
616 | 617 |
hashrefs for each row. |
617 | 618 |
|
619 |
|
|
620 |
=item selectall_array_query FORM,DBH,QUERY,ARRAY |
|
621 |
|
|
622 |
Deprecated, see C<selectcol_array_query> |
|
623 |
|
|
624 |
=item selectcol_array_query FORM,DBH,QUERY,ARRAY |
|
625 |
|
|
626 |
Prepares and executes a query using DBUtils functions, retrieves the values of |
|
627 |
the first result column and returns the values as an array. |
|
628 |
|
|
618 | 629 |
=item selectall_as_map FORM,DBH,QUERY,KEY_COL,VALUE_COL,ARRAY |
619 | 630 |
|
620 | 631 |
Prepares and executes a query using DBUtils functions, retrieves all data from |
... | ... | |
704 | 715 |
$query = qq|SELECT nextval('glid')|; |
705 | 716 |
($new_id) = selectrow_query($form, $dbh, $query); |
706 | 717 |
|
718 |
=item Retrieving all values from a column: |
|
719 |
|
|
720 |
$query = qq|SELECT id FROM units|; |
|
721 |
@units = selectcol_array_query($form, $dbh, $query); |
|
722 |
|
|
707 | 723 |
=item Using binding values: |
708 | 724 |
|
709 | 725 |
$query = qq|UPDATE ar SET paid = amount + paid, storno = 't' WHERE id = ?|; |
Auch abrufbar als: Unified diff
SL::DBUtils - selectall_array_query -> selectcol_array_query
selectall_array_query durch selectcol_array_query ersetzt.
Intern wird nun die DBI-Funktion selectcol_arrayref verwendet, anstatt
dies manuell per Schleife zu machen. Der Name selectall_array_query war
irreführend und der neue Name entspricht nun dem, was man erwartet.