Bug 32413: Fix repeated param names for JSON report

This patch fixes repeated param names for JSON report.

To test:

1) Create a report
    SELECT count(*) from items where homebranch = <<Branchcode>>
    UNION ALL
    SELECT count(*) from deleteditems where homebranch = <<Branchcode>>
2) Run the report as JSON, cgi-bin/koha/svc/report?id=<id>&sql_params=<Branchcode>
3) Check that the second value is 0
4) Apply the patch
5) Run the report as JSON again
6) Check that the second value has the correct value
7) prove t/db_dependent/Koha/Reports.t

Sponsored-by: Koha-Suomi Oy
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Johanna Räisä 2024-10-08 13:46:24 +03:00 committed by Katrin Fischer
parent 4b4a33c877
commit c2cc6869dd
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
2 changed files with 8 additions and 2 deletions

View File

@ -194,6 +194,12 @@ sub prep_report {
}
my %lookup;
unless ( scalar @$param_names ) {
my @placeholders = $sql =~ /<<([^<>]+)>>/g;
foreach my $placeholder (@placeholders) {
push @$param_names, $placeholder unless grep { $_ eq $placeholder } @$param_names;
}
}
@lookup{@$param_names} = @$sql_params;
@split = split /<<|>>/, $sql;
for ( my $i = 0 ; $i < $#split / 2 ; $i++ ) {

View File

@ -66,8 +66,8 @@ subtest 'prep_report' => sub {
($sql, undef) = $report->prep_report( ['Test|list','Another'],["1\n12\n\r243",'the other'] );
is( $sql, qq{SELECT * FROM items WHERE itemnumber IN ('1','12','243') AND 'the other' AND ('1','12','243') /* saved_sql.id: $id */},'Expected sql generated correctly with multiple params and names');
($sql, undef) = $report->prep_report( [],["1\n12\n\r243",'the other',"42\n32\n22\n12"] );
is( $sql, qq{SELECT * FROM items WHERE itemnumber IN ('1','12','243') AND 'the other' AND ('42','32','22','12') /* saved_sql.id: $id */},'Expected sql generated correctly with multiple params and no names');
($sql, undef) = $report->prep_report( [],["1\n12\n\r243",'the other'] );
is( $sql, qq{SELECT * FROM items WHERE itemnumber IN ('1','12','243') AND 'the other' AND ('1','12','243') /* saved_sql.id: $id */},'Expected sql generated correctly with multiple params and no names');
$report->savedsql(
q{SELECT i.itemnumber, i.itemnumber as Exemplarnummber, [[i.itemnumber| itemnumber for batch]] FROM items})