line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::OptimalQuery::CSV; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
886
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
4
|
no warnings qw( uninitialized ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
6
|
1
|
|
|
1
|
|
4
|
use base 'CGI::OptimalQuery::Base'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
108
|
|
7
|
1
|
|
|
1
|
|
6
|
use CGI(); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
376
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub output { |
10
|
0
|
|
|
0
|
0
|
|
my $o = shift; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
my $title = $o->{schema}->{title}; |
13
|
0
|
|
|
|
|
|
$title =~ s/\W//g; |
14
|
0
|
|
|
|
|
|
my @t = localtime; |
15
|
0
|
|
|
|
|
|
$title .= '_'.($t[5] + 1900).($t[4] + 1).$t[3].$t[2].$t[1]; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
$$o{output_handler}->(CGI::header(-type => 'text/csv', -attachment => "$title.csv")); |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $selCols = $o->get_usersel_cols(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# print header |
22
|
0
|
|
|
|
|
|
my @buffer; |
23
|
0
|
|
|
|
|
|
foreach my $i (0 .. $#$selCols) { |
24
|
0
|
|
|
|
|
|
my $col = $o->get_nice_name($o->get_usersel_cols->[$i]); |
25
|
0
|
|
|
|
|
|
$col =~ s/\"/""/g; |
26
|
0
|
|
|
|
|
|
push @buffer, '"'.$col.'"'; |
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
|
$$o{output_handler}->(join(',', @buffer)."\n"); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# print data |
31
|
0
|
|
|
|
|
|
while (my $rec = $o->fetch()) { |
32
|
0
|
|
|
|
|
|
@buffer = (); |
33
|
0
|
|
|
|
|
|
foreach my $col (@$selCols) { |
34
|
0
|
|
|
|
|
|
my $val = $o->get_val($col); |
35
|
0
|
|
|
|
|
|
$val =~ s/\"/""/g; |
36
|
0
|
|
|
|
|
|
$val =~ s/[\r\n]+/; /g; |
37
|
0
|
|
|
|
|
|
$val =~ s/[^!-~\s]//g; |
38
|
0
|
|
|
|
|
|
push @buffer, '"'.$val.'"'; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
$$o{output_handler}->(join(',', @buffer)."\n"); |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
$o->finish(); |
43
|
0
|
|
|
|
|
|
return undef; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |