-
-# preparing calculation
- my $strcalc ;
-
-# Processing average loanperiods
- $strcalc .= "SELECT items.barcode, biblio.title, biblio.biblionumber, biblio.author";
- $strcalc .= " , $colfield " if ($colfield);
- $strcalc .= " FROM (items LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber LEFT JOIN biblio ON biblio.biblionumber=items.biblionumber) LEFT JOIN issues ON issues.itemnumber=items.itemnumber WHERE issues.itemnumber is null";
-# @$filters[0]=~ s/\*/%/g if (@$filters[0]);
-# $strcalc .= " AND issues.timestamp <= '" . @$filters[0] ."'" if ( @$filters[0] );
-# @$filters[1]=~ s/\*/%/g if (@$filters[1]);
-# $strcalc .= " AND issues.timestamp >= '" . @$filters[1] ."'" if ( @$filters[1] );
-# @$filters[2]=~ s/\*/%/g if (@$filters[2]);
-# $strcalc .= " AND issues.returndate <= '" . @$filters[2] ."'" if ( @$filters[2] );
-# @$filters[3]=~ s/\*/%/g if (@$filters[3]);
-# $strcalc .= " AND issues.returndate >= '" . @$filters[3] ."'" if ( @$filters[3] );
- @$filters[0]=~ s/\*/%/g if (@$filters[0]);
- $strcalc .= " AND items.homebranch like '" . @$filters[0] ."'" if ( @$filters[0] );
- @$filters[1]=~ s/\*/%/g if (@$filters[1]);
- $strcalc .= " AND biblioitems.itemtype like '" . @$filters[1] ."'" if ( @$filters[1] );
-
- $strcalc .= " group by items.itemnumber";
- $strcalc .= ", $colfield" if ($column);
- $strcalc .= " order by $colfield " if ($colfield);
- my $max;
- if (@loopcol) {
- $max = $line*@loopcol;
- } else { $max=$line;}
- $strcalc .= " LIMIT 0,$max" if ($line);
- warn "SQL :". $strcalc;
-
- my $dbcalc = $dbh->prepare($strcalc);
- $dbcalc->execute;
-# warn "filling table";
- my $previous_col;
- my $i=1;
- while (my @data = $dbcalc->fetchrow) {
- my ($barcode,$title,$bibnum,$author, $col )=@data;
- $col = "zzEMPTY" if ($col eq undef);
- $i=1 if (($previous_col) and not($col eq $previous_col));
- $table[$i]->{$col}->{'barcode'}=$barcode;
- $table[$i]->{$col}->{'title'}=$title;
- $table[$i]->{$col}->{'bibnum'}=$bibnum;
- $table[$i]->{$col}->{'author'}=$author;
-# warn " ".$i." ".$col. " ".$row;
- $i++;
- $previous_col=$col;
+ if ($column) {
+ foreach (sort keys %columns) {
+ my (@more_exe_args) = @exe_args; # execute(@exe_args,$_) would fail when the array is empty.
+ push @more_exe_args, $_; # but @more_exe_args will work
+ $dbcalc->execute(@more_exe_args) or die "Query execute(@more_exe_args) failed: $query";
+ while (my $data = $dbcalc->fetchrow_hashref) {
+ my $col = $data->{col} || 'NULL';
+ $tables{$col} or $tables{$col} = [];
+ push @{$tables{$col}}, $data;
+ }
+ }
+ } else {
+ (scalar @exe_args) ? $dbcalc->execute(@exe_args) : $dbcalc->execute;
+ while (my $data = $dbcalc->fetchrow_hashref) {
+ my $col = $data->{col} || 'NULL';
+ $tables{$col} or $tables{$col} = [];
+ push @{$tables{$col}}, $data;
+ }