Lines 556-566
and that the number placeholders matches the number of parameters.
Link Here
|
556 |
=cut |
556 |
=cut |
557 |
|
557 |
|
558 |
sub execute_query { |
558 |
sub execute_query { |
559 |
|
|
|
560 |
my $params = shift; |
559 |
my $params = shift; |
561 |
my $sql = $params->{sql}; |
560 |
my $sql = $params->{sql}; |
562 |
my $offset = $params->{offset} || 0; |
561 |
my $offset = $params->{offset} || 0; |
563 |
my $limit = $params->{limit} || C4::Context->config('report_results_limit') || 999999; |
562 |
my $limit = $params->{limit} || C4::Context->config('report_results_limit') || 999999; |
564 |
my $sql_params = defined $params->{sql_params} ? $params->{sql_params} : []; |
563 |
my $sql_params = defined $params->{sql_params} ? $params->{sql_params} : []; |
565 |
my $report_id = $params->{report_id}; |
564 |
my $report_id = $params->{report_id}; |
566 |
|
565 |
|
Lines 572-606
sub execute_query {
Link Here
|
572 |
|
571 |
|
573 |
Koha::Logger->get->debug("Report - execute_query($sql, $offset, $limit)"); |
572 |
Koha::Logger->get->debug("Report - execute_query($sql, $offset, $limit)"); |
574 |
|
573 |
|
575 |
my ( $is_sql_valid, $errors ) = Koha::Report->new({ savedsql => $sql })->is_sql_valid; |
574 |
my ( $is_sql_valid, $errors ) = Koha::Report->new( { savedsql => $sql } )->is_sql_valid; |
576 |
return (undef, @{$errors}[0]) unless $is_sql_valid; |
575 |
return ( undef, @{$errors}[0] ) unless $is_sql_valid; |
577 |
|
576 |
|
578 |
foreach my $sql_param ( @$sql_params ){ |
577 |
foreach my $sql_param (@$sql_params) { |
579 |
if ( $sql_param =~ m/\n/ ){ |
578 |
if ( $sql_param =~ m/\n/ ) { |
580 |
my @list = split /\n/, $sql_param; |
579 |
my @list = split /\n/, $sql_param; |
581 |
my @quoted_list; |
580 |
my @quoted_list; |
582 |
foreach my $item ( @list ){ |
581 |
foreach my $item (@list) { |
583 |
$item =~ s/\r//; |
582 |
$item =~ s/\r//; |
584 |
push @quoted_list, C4::Context->dbh->quote($item); |
583 |
push @quoted_list, C4::Context->dbh->quote($item); |
585 |
} |
584 |
} |
586 |
$sql_param = "(".join(",",@quoted_list).")"; |
585 |
$sql_param = "(" . join( ",", @quoted_list ) . ")"; |
587 |
} |
586 |
} |
588 |
} |
587 |
} |
589 |
|
588 |
|
590 |
my ($useroffset, $userlimit); |
589 |
my ( $useroffset, $userlimit ); |
591 |
|
590 |
|
592 |
# Grab offset/limit from user supplied LIMIT and drop the LIMIT so we can control pagination |
591 |
# Grab offset/limit from user supplied LIMIT and drop the LIMIT so we can control pagination |
593 |
($sql, $useroffset, $userlimit) = strip_limit($sql); |
592 |
( $sql, $useroffset, $userlimit ) = strip_limit($sql); |
594 |
|
593 |
|
595 |
Koha::Logger->get->debug( |
594 |
Koha::Logger->get->debug( |
596 |
sprintf "User has supplied (OFFSET,) LIMIT = %s, %s", |
595 |
sprintf "User has supplied (OFFSET,) LIMIT = %s, %s", |
597 |
$useroffset, ( defined($userlimit) ? $userlimit : 'UNDEF' ) ); |
596 |
$useroffset, ( defined($userlimit) ? $userlimit : 'UNDEF' ) |
|
|
597 |
); |
598 |
|
598 |
|
599 |
$offset += $useroffset; |
599 |
$offset += $useroffset; |
600 |
if (defined($userlimit)) { |
600 |
if ( defined($userlimit) ) { |
601 |
if ($offset + $limit > $userlimit ) { |
601 |
if ( $offset + $limit > $userlimit ) { |
602 |
$limit = $userlimit - $offset; |
602 |
$limit = $userlimit - $offset; |
603 |
} elsif ( ! $offset && $limit < $userlimit ) { |
603 |
} elsif ( !$offset && $limit < $userlimit ) { |
604 |
$limit = $userlimit; |
604 |
$limit = $userlimit; |
605 |
} |
605 |
} |
606 |
} |
606 |
} |
Lines 616-631
sub execute_query {
Link Here
|
616 |
->info("Report starting: $report_id") if $report_id; |
616 |
->info("Report starting: $report_id") if $report_id; |
617 |
|
617 |
|
618 |
my $sth = $dbh->prepare($sql); |
618 |
my $sth = $dbh->prepare($sql); |
619 |
eval { |
619 |
eval { $sth->execute( @$sql_params, $offset, $limit ); }; |
620 |
$sth->execute(@$sql_params, $offset, $limit); |
|
|
621 |
}; |
622 |
warn $@ if $@; |
620 |
warn $@ if $@; |
623 |
|
621 |
|
624 |
Koha::Logger->get( { prefix => 0, interface => 'reports', category => 'execute.time.end' } ) |
622 |
Koha::Logger->get( { prefix => 0, interface => 'reports', category => 'execute.time.end' } ) |
625 |
->info("Report finished: $report_id") if $report_id; |
623 |
->info("Report finished: $report_id") if $report_id; |
626 |
|
624 |
|
627 |
return ( $sth, { queryerr => $sth->errstr } ) if ($sth->err); |
625 |
return ( $sth, { queryerr => $sth->errstr } ) if ( $sth->err ); |
628 |
return ( $sth ); |
626 |
return ($sth); |
629 |
} |
627 |
} |
630 |
|
628 |
|
631 |
=head2 save_report($sql,$name,$type,$notes) |
629 |
=head2 save_report($sql,$name,$type,$notes) |
632 |
- |
|
|