From 1982403c36deddf8095a832d47f7b1367d6e6e68 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 30 Mar 2022 12:25:42 +0000 Subject: [PATCH] Bug 26669: Adjust POD Signed-off-by: Nick Clemens Signed-off-by: Fridolin Somers Signed-off-by: Kyle M Hall --- C4/Reports/Guided.pm | 102 ++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm index cefecca892..986fb0e97f 100644 --- a/C4/Reports/Guided.pm +++ b/C4/Reports/Guided.pm @@ -464,35 +464,15 @@ sub nb_rows { return $results ? $results->[0] : 0; } -=head2 execute_query - - ($sth, $error) = execute_query($sql, $offset, $limit[, \@sql_params]) - - -This function returns a DBI statement handler from which the caller can -fetch the results of the SQL passed via C<$sql>. - -If passed any query other than a SELECT, or if there is a DB error, -C<$errors> is returned, and is a hashref containing the error after this -manner: - -C<$error->{'sqlerr'}> contains the offending SQL keyword. -C<$error->{'queryerr'}> contains the native db engine error returned -for the query. - -C<$offset>, and C<$limit> are required parameters. +=head2 select_2_select_count -C<\@sql_params> is an optional list of parameter values to paste in. -The caller is responsible for making sure that C<$sql> has placeholders -and that the number placeholders matches the number of parameters. + returns $sql, $offset, $limit + $sql returned will be transformed to: + ~ remove any LIMIT clause + ~ replace SELECT clause w/ SELECT count(*) =cut -# returns $sql, $offset, $limit -# $sql returned will be transformed to: -# ~ remove any LIMIT clause -# ~ repace SELECT clause w/ SELECT count(*) - sub select_2_select_count { # Modify the query passed in to create a count query... (I think this covers all cases -crn) my ($sql) = strip_limit(shift) or return; @@ -500,25 +480,29 @@ sub select_2_select_count { return $sql; } -# This removes the LIMIT from the query so that a custom one can be specified. -# Usage: -# ($new_sql, $offset, $limit) = strip_limit($sql); -# -# Where: -# $sql is the query to modify -# $new_sql is the resulting query -# $offset is the offset value, if the LIMIT was the two-argument form, -# 0 if it wasn't otherwise given. -# $limit is the limit value -# -# Notes: -# * This makes an effort to not break subqueries that have their own -# LIMIT specified. It does that by only removing a LIMIT if it comes after -# a WHERE clause (which isn't perfect, but at least should make more cases -# work - subqueries with a limit in the WHERE will still break.) -# * If your query doesn't have a WHERE clause then all LIMITs will be -# removed. This may break some subqueries, but is hopefully rare enough -# to not be a big issue. +=head2 strip_limit +This removes the LIMIT from the query so that a custom one can be specified. +Usage: + ($new_sql, $offset, $limit) = strip_limit($sql); + +Where: + $sql is the query to modify + $new_sql is the resulting query + $offset is the offset value, if the LIMIT was the two-argument form, + 0 if it wasn't otherwise given. + $limit is the limit value + +Notes: + * This makes an effort to not break subqueries that have their own + LIMIT specified. It does that by only removing a LIMIT if it comes after + a WHERE clause (which isn't perfect, but at least should make more cases + work - subqueries with a limit in the WHERE will still break.) + * If your query doesn't have a WHERE clause then all LIMITs will be + removed. This may break some subqueries, but is hopefully rare enough + to not be a big issue. + +=cut + sub strip_limit { my ($sql) = @_; @@ -539,6 +523,36 @@ sub strip_limit { } } +=head2 execute_query + + ($sth, $error) = execute_query({ + sql => $sql, + offset => $offset, + limit => $limit + sql_params => \@sql_params], + report_id => $report_id + }) + + +This function returns a DBI statement handler from which the caller can +fetch the results of the SQL passed via C<$sql>. + +If passed any query other than a SELECT, or if there is a DB error, +C<$errors> is returned, and is a hashref containing the error after this +manner: + +C<$error->{'sqlerr'}> contains the offending SQL keyword. +C<$error->{'queryerr'}> contains the native db engine error returned +for the query. + +C<$offset>, and C<$limit> are required parameters. + +C<\@sql_params> is an optional list of parameter values to paste in. +The caller is responsible for making sure that C<$sql> has placeholders +and that the number placeholders matches the number of parameters. + +=cut + sub execute_query { my $params = shift; -- 2.39.5