slf-signature/19-19.sql
[SQL2XLS] / sql2xls.cgi
index 5f23394..041e198 100755 (executable)
@@ -99,7 +99,7 @@ $sql_dir .= "/$reports_path" if -e "$sql_dir/$reports_path";
 
 require_config;
 
-warn "# reading SQL queries from $sql_dir\n" if $debug;
+warn "SQL queries from $sql_dir\n";
 
 opendir(DIR, $sql_dir) || die "can't opendir $sql_dir: $!";
 my @sql_files = sort grep { /\.sql$/i && -f "$sql_dir/$_" } readdir(DIR);
@@ -195,12 +195,12 @@ foreach my $sql_file (@sql_files) {
 
        foreach my $sql ( split(/;/, $full_sql ) ) {
 
-               warn "SQL: $sql\n" if $debug;
+               warn "SQL: $sql\n";
 
                my $sth = $dbh->prepare($sql);
                $sth->execute();
 
-               next unless $sth->{NAME}; # $sth->rows doesn't work for insert into with MySQL
+               next unless $sth->{NAME} && $sth->rows > 0; # $sth->rows alone doesn't work for insert into with MySQL
 
                my @types = eval {
                        map { $dbh->type_info($_) ? $dbh->type_info($_)->{TYPE_NAME} : '?' } @{ $sth->{TYPE} };
@@ -224,6 +224,7 @@ foreach my $sql_file (@sql_files) {
                                        warn "## heuristic date time: $1T$2\n" if $debug;
                                        $worksheet->write_date_time( $row, $col, "$1T$2", $date_format );
                                } else {
+                                       $data = "'" . $data if $data =~ m/^=/; # escape data which looks like formula
                                        $worksheet->write($row, $col, _c( $data ) );
                                }
                        }