line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
# vim:ts=4:sw=4:aw:ai: |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# DBI::Format::CSV - a package for displaying result tables |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright (c) 2001, 2002 Thomas A. Lowery |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# The DBI::Shell::CSV module is free software; you can redistribute |
9
|
|
|
|
|
|
|
# it and/or modify it under the same terms as Perl itself. |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
118
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package DBI::Format::CSV; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '11.96_02'; # TRIAL VERSION |
17
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
@DBI::Format::CSV::ISA = qw(DBI::Format::Base); |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
9
|
use Text::Abbrev; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
69
|
|
22
|
1
|
|
|
1
|
|
6
|
use Text::Reform qw(form break_with); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
23
|
1
|
|
|
1
|
|
1168
|
use Text::CSV_XS; |
|
1
|
|
|
|
|
12220
|
|
|
1
|
|
|
|
|
431
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub header { |
26
|
3
|
|
|
3
|
0
|
14
|
my($self, $sth, $fh, $sep) = @_; |
27
|
3
|
|
|
|
|
32
|
$self->{'fh'} = $self->setup_fh($fh); |
28
|
3
|
|
|
|
|
93
|
$self->{'sth'} = $sth; |
29
|
3
|
|
|
|
|
15
|
$self->{'data'} = []; |
30
|
3
|
|
|
|
|
10
|
$self->{'formats'} = []; |
31
|
3
|
50
|
|
|
|
14
|
$self->{sep} = $sep if defined $sep; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$self->{csv_obj} = Text::CSV_XS->new({ |
34
|
|
|
|
|
|
|
binary => 1, |
35
|
|
|
|
|
|
|
sep_char => $self->{sep}, |
36
|
3
|
|
|
|
|
55
|
always_quote => 1, |
37
|
|
|
|
|
|
|
}); |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
625
|
my $names = $sth->{'NAME'}; |
40
|
3
|
|
|
|
|
10
|
my $csv = $self->{csv_obj}; |
41
|
3
|
|
|
|
|
83
|
my $status = $csv->print($fh, $names); |
42
|
3
|
|
|
|
|
183
|
$fh->print( "\n" ); |
43
|
3
|
|
|
|
|
43
|
return 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub row { |
47
|
30
|
|
|
30
|
0
|
57
|
my($self, $orig_row) = @_; |
48
|
30
|
|
|
|
|
44
|
my $i = 0; |
49
|
30
|
|
|
|
|
52
|
my @row = @$orig_row; # don't mess with the original row |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# default value for null, is blank. |
52
|
30
|
|
50
|
|
|
111
|
my $null = $self->{'null'} || ''; |
53
|
30
|
|
|
|
|
51
|
my $columns = $self->{'columns'}; |
54
|
|
|
|
|
|
|
|
55
|
30
|
|
|
|
|
46
|
my $breaks = $self->{'breaks'}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
map { |
58
|
30
|
50
|
|
|
|
56
|
if (!defined($_)) { |
|
150
|
|
|
|
|
245
|
|
59
|
0
|
|
|
|
|
0
|
$_ = $null; |
60
|
|
|
|
|
|
|
} else { |
61
|
150
|
|
|
|
|
246
|
$_ =~ s/\n/\\n/g; |
62
|
150
|
|
|
|
|
195
|
$_ =~ s/\t/\\t/g; |
63
|
150
|
|
|
|
|
187
|
$_ =~ s/\r/\\r/g; |
64
|
150
|
|
|
|
|
224
|
$_ =~ s/[\000-\037\177-\237]/./g; |
65
|
|
|
|
|
|
|
} |
66
|
150
|
|
|
|
|
197
|
++$i; |
67
|
|
|
|
|
|
|
} @row; |
68
|
|
|
|
|
|
|
|
69
|
30
|
|
|
|
|
56
|
my $fh = $self->{'fh'}; |
70
|
30
|
|
|
|
|
43
|
my $csv = $self->{csv_obj}; |
71
|
30
|
|
|
|
|
178
|
my $status = $csv->print($fh, \@row); |
72
|
30
|
|
|
|
|
1047
|
$fh->print( "\n" ); |
73
|
|
|
|
|
|
|
|
74
|
30
|
|
|
|
|
441
|
return ++$self->{rows}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub trailer { |
79
|
3
|
|
|
3
|
0
|
8
|
my $self = shift; |
80
|
|
|
|
|
|
|
# $self->SUPER::trailer(@_); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 NAME |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
DBI::Format::CSV - A package for displaying result tables |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SYNOPSIS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 DESCRIPTION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
THIS PACKAGE IS STILL VERY EXPERIMENTAL. THINGS WILL CHANGE. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHOR AND COPYRIGHT |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Orignal Format module is Copyright (c) 1997, 1998 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Jochen Wiedmann |
100
|
|
|
|
|
|
|
Am Eisteich 9 |
101
|
|
|
|
|
|
|
72555 Metzingen |
102
|
|
|
|
|
|
|
Germany |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Email: joe@ispsoft.de |
105
|
|
|
|
|
|
|
Phone: +49 7123 14887 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
SQLMinus is Copyright (c) 2001, 2002 Thomas A. Lowery |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
The DBI::Format::CSV module is free software; you can redistribute it and/or |
110
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SEE ALSO |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
L, L, L |