Bugzilla – Attachment 173437 Details for
Bug 32413
JSON reports shows inaccurate results with repeated parameters
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32413: Fix repeated param names for JSON report
Bug-32413-Fix-repeated-param-names-for-JSON-report.patch (text/plain), 2.78 KB, created by
Martin Renvoize (ashimema)
on 2024-10-28 08:55:05 UTC
(
hide
)
Description:
Bug 32413: Fix repeated param names for JSON report
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-10-28 08:55:05 UTC
Size:
2.78 KB
patch
obsolete
>From e6138f990f6cd551505fd0680792bb6d3adca220 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Johanna=20R=C3=A4is=C3=A4?= <johanna.raisa@gmail.com> >Date: Tue, 8 Oct 2024 13:46:24 +0300 >Subject: [PATCH] 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> >--- > Koha/Report.pm | 6 ++++++ > t/db_dependent/Koha/Reports.t | 4 ++-- > 2 files changed, 8 insertions(+), 2 deletions(-) > >diff --git a/Koha/Report.pm b/Koha/Report.pm >index 4ac42ffa477..0a36f81b90d 100644 >--- a/Koha/Report.pm >+++ b/Koha/Report.pm >@@ -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++ ) { >diff --git a/t/db_dependent/Koha/Reports.t b/t/db_dependent/Koha/Reports.t >index 941a89ce288..19bee5bd274 100755 >--- a/t/db_dependent/Koha/Reports.t >+++ b/t/db_dependent/Koha/Reports.t >@@ -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}) >-- >2.47.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 32413
:
172555
|
172565
| 173437