From c50068d7feb4c23c1734ed7dd107add9b4eaaee9 Mon Sep 17 00:00:00 2001 From: hdl Date: Mon, 28 Nov 2005 10:40:32 +0000 Subject: [PATCH] Bug Fixes : Managing null values and filling some collumns that were left empty owed to the LIMIT in SQL statements. --- reports/bor_issues_top.pl | 34 ++++++++++++++++------------------ reports/cat_issues_top.pl | 33 ++++++++++++++------------------- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/reports/bor_issues_top.pl b/reports/bor_issues_top.pl index 317822adb2..11d4602a35 100755 --- a/reports/bor_issues_top.pl +++ b/reports/bor_issues_top.pl @@ -243,7 +243,7 @@ sub calculate { while (my ($celvalue) = $sth2->fetchrow) { my %cell; - $cell{coltitle} = $celvalue; + $cell{'coltitle'} = ($celvalue?$celvalue:"NULL"); push @loopcol, \%cell; } # warn "fin des titres colonnes"; @@ -296,31 +296,29 @@ sub calculate { $strcalc .= " group by borrowers.borrowernumber"; $strcalc .= ", $colfield" if ($column); - $strcalc .= " order by "; - $strcalc .= "$colfield, " if ($colfield); - $strcalc .= "RANK DESC "; - my $max; - if (@loopcol) { - $max = $line*@loopcol; - } else { $max=$line;} - $strcalc .= " LIMIT 0,$max"; + $strcalc .= " order by RANK DESC"; + $strcalc .= ",$colfield " if ($colfield); +# my $max; +# if (@loopcol) { +# $max = $line*@loopcol; +# } else { $max=$line;} +# $strcalc .= " LIMIT 0,$max"; warn "SQL :". $strcalc; my $dbcalc = $dbh->prepare($strcalc); $dbcalc->execute; # warn "filling table"; my $previous_col; - my $i=1; + my %indice; while (my @data = $dbcalc->fetchrow) { my ($row, $rank, $id, $col )=@data; $col = "zzEMPTY" if ($col eq undef); - $i=1 if (($previous_col) and not($col eq $previous_col)); - $table[$i]->{$col}->{'name'}=$row; - $table[$i]->{$col}->{'count'}=$rank; - $table[$i]->{$col}->{'link'}=$id; - warn " ".$i." ".$col. " ".$row; - $i++; - $previous_col=$col; + $indice{$col}=1 if (not($indice{$col})); + $table[$indice{$col}]->{$col}->{'name'}=$row; + $table[$indice{$col}]->{$col}->{'count'}=$rank; + $table[$indice{$col}]->{$col}->{'link'}=$id; +# warn " ".$i." ".$col. " ".$row; + $indice{$col}++; } push @loopcol,{coltitle => "Global"} if not($column); @@ -328,7 +326,7 @@ sub calculate { for ($i=1; $i<=$line;$i++) { my @loopcell; warn " $i"; - #@loopcol ensures the order for columns is common with column titles + #@loborrowersopcol ensures the order for columns is common with column titles # and the number matches the number of columns my $colcount=0; foreach my $col ( @loopcol ) { diff --git a/reports/cat_issues_top.pl b/reports/cat_issues_top.pl index fddcf6d58b..c0e1040293 100755 --- a/reports/cat_issues_top.pl +++ b/reports/cat_issues_top.pl @@ -251,10 +251,7 @@ sub calculate { while (my ($celvalue) = $sth2->fetchrow) { my %cell; - # my %ft; - # warn "coltitle :".$celvalue; - $cell{coltitle} = $celvalue; - # $ft{totalcol} = 0; + $cell{coltitle} = ($celvalue?$celvalue:"NULL"); push @loopcol, \%cell; } # warn "fin des titres colonnes"; @@ -307,31 +304,29 @@ sub calculate { $strcalc .= " group by biblio.biblionumber"; $strcalc .= ", $colfield" if ($column); - $strcalc .= " order by "; - $strcalc .= "$colfield, " if ($colfield); - $strcalc .= "RANK DESC "; - my $max; - if (@loopcol) { - $max = $line*@loopcol; - } else { $max=$line;} - $strcalc .= " LIMIT 0,$max"; + $strcalc .= " order by RANK DESC"; + $strcalc .= ", $colfield " if ($colfield); +# my $max; +# if (@loopcol) { +# $max = $line*@loopcol; +# } else { $max=$line;} +# $strcalc .= " LIMIT 0,$max"; warn "SQL :". $strcalc; my $dbcalc = $dbh->prepare($strcalc); $dbcalc->execute; # warn "filling table"; my $previous_col; - my $i=1; + my %indice; while (my @data = $dbcalc->fetchrow) { my ($row, $rank, $id, $col )=@data; $col = "zzEMPTY" if ($col eq undef); - $i=1 if (($previous_col) and not($col eq $previous_col)); - $table[$i]->{$col}->{'name'}=$row; - $table[$i]->{$col}->{'count'}=$rank; - $table[$i]->{$col}->{'link'}=$id; + $indice{$col}=1 if (not($indice{$col})); + $table[$indice{$col}]->{$col}->{'name'}=$row; + $table[$indice{$col}]->{$col}->{'count'}=$rank; + $table[$indice{$col}]->{$col}->{'link'}=$id; # warn " ".$i." ".$col. " ".$row; - $i++; - $previous_col=$col; + $indice{$col}++; } push @loopcol,{coltitle => "Global"} if not($column);