Bug 27380: Move get_prepped_report to object and use for svc/reports
[koha-ffzg.git] / C4 / Reports / Guided.pm
index 0a592b5..a76d86b 100644 (file)
@@ -445,8 +445,11 @@ sub nb_rows {
     $dbh->{RaiseError} = $RaiseError;
     $dbh->{PrintError} = $PrintError;
     if ($@) { # To catch "Duplicate column name" caused by the derived table, or any other syntax error
-        $sth = $dbh->prepare($sql);
-        $sth->execute;
+        eval {
+            $sth = $dbh->prepare($sql);
+            $sth->execute;
+        };
+        warn $@ if $@;
         # Loop through the complete results, fetching 1,000 rows at a time.  This
         # lowers memory requirements but increases execution time.
         while (my $rows = $sth->fetchall_arrayref(undef, 1000)) {
@@ -554,6 +557,18 @@ sub execute_query {
         return (undef, { queryerr => 'Missing SELECT'} );
     }
 
+    foreach my $sql_param ( @$sql_params ){
+        if ( $sql_param =~ m/\n/ ){
+            my @list = split /\n/, $sql_param;
+            my @quoted_list;
+            foreach my $item ( @list ){
+                $item =~ s/\r//;
+              push @quoted_list, C4::Context->dbh->quote($item);
+            }
+            $sql_param = "(".join(",",@quoted_list).")";
+        }
+    }
+
     my ($useroffset, $userlimit);
 
     # Grab offset/limit from user supplied LIMIT and drop the LIMIT so we can control pagination
@@ -576,7 +591,10 @@ sub execute_query {
     $dbh->do( 'UPDATE saved_sql SET last_run = NOW() WHERE id = ?', undef, $report_id ) if $report_id;
 
     my $sth = $dbh->prepare($sql);
-    $sth->execute(@$sql_params, $offset, $limit);
+    eval {
+        $sth->execute(@$sql_params, $offset, $limit);
+    };
+    warn $@ if $@;
 
     return ( $sth, { queryerr => $sth->errstr } ) if ($sth->err);
     return ( $sth );
@@ -910,6 +928,7 @@ Returns a hash containig all reserved words
 sub GetReservedAuthorisedValues {
     my %reserved_authorised_values =
             map { $_ => 1 } ( 'date',
+                              'list',
                               'branches',
                               'itemtypes',
                               'cn_source',