line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
# vim:ts=2:sw=2:aw:ai:sta:nows |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# DBI::Format - a package for displaying result tables |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright (c) 1998 Jochen Wiedmann |
7
|
|
|
|
|
|
|
# Copyright (c) 1998 Tim Bunce |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# The DBI::Shell:Result module is free software; you can redistribute |
10
|
|
|
|
|
|
|
# it and/or modify it under the same terms as Perl itself. |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# Author: Jochen Wiedmann |
13
|
|
|
|
|
|
|
# Am Eisteich 9 |
14
|
|
|
|
|
|
|
# 72555 Metzingen |
15
|
|
|
|
|
|
|
# Germany |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# Email: joe@ispsoft.de |
18
|
|
|
|
|
|
|
# Phone: +49 7123 14881 |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
|
21
|
7
|
|
|
7
|
|
51
|
use strict; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
392
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
package DBI::Format; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = '11.97'; # VERSION |
26
|
|
|
|
|
|
|
|
27
|
7
|
|
|
7
|
|
48
|
use Text::Abbrev; |
|
7
|
|
|
|
|
26
|
|
|
7
|
|
|
|
|
3375
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub available_formatters { |
30
|
22
|
|
|
22
|
0
|
46
|
my ($use_abbrev) = @_; |
31
|
22
|
|
|
|
|
51
|
my @fmt; |
32
|
22
|
|
|
|
|
58
|
my @dir = grep { -d "$_/DBI/Format" } @INC; |
|
242
|
|
|
|
|
3182
|
|
33
|
22
|
|
|
|
|
84
|
foreach my $dir (@dir) { |
34
|
66
|
50
|
|
|
|
1891
|
opendir DIR, "$dir/DBI/Format" or warn "Unable to read $dir/DBI: $!\n"; |
35
|
66
|
100
|
|
|
|
1378
|
push @fmt, map { m/^(\w+)\.pm$/i ? ($1) : () } readdir DIR; |
|
264
|
|
|
|
|
1300
|
|
36
|
66
|
|
|
|
|
813
|
closedir DIR; |
37
|
|
|
|
|
|
|
} |
38
|
22
|
|
|
|
|
86
|
my %fmt = map { (lc($_) => "DBI::Format::$_") } @fmt; |
|
132
|
|
|
|
|
652
|
|
39
|
22
|
|
|
|
|
90
|
$fmt{box} = "DBI::Format::Box"; |
40
|
22
|
|
|
|
|
54
|
$fmt{partbox} = "DBI::Format::PartBox"; |
41
|
22
|
|
|
|
|
69
|
$fmt{neat} = "DBI::Format::Neat"; |
42
|
22
|
|
|
|
|
49
|
$fmt{raw} = "DBI::Format::Raw"; |
43
|
22
|
|
|
|
|
47
|
$fmt{string} = "DBI::Format::String"; |
44
|
22
|
|
|
|
|
51
|
$fmt{html} = "DBI::Format::HTML"; |
45
|
22
|
|
|
|
|
59
|
my $formatters = \%fmt; |
46
|
22
|
50
|
|
|
|
67
|
if ($use_abbrev) { |
47
|
22
|
|
|
|
|
139
|
$formatters = abbrev(keys %fmt); |
48
|
22
|
|
|
|
|
4785
|
foreach my $abbrev (sort keys %$formatters) { |
49
|
792
|
|
50
|
|
|
1421
|
$formatters->{$abbrev} = $fmt{ $formatters->{$abbrev} } || die; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
22
|
|
|
|
|
120
|
return $formatters; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub formatter { |
57
|
22
|
|
|
22
|
0
|
75
|
my ($class, $mode, $use_abbrev) = @_; |
58
|
22
|
|
|
|
|
59
|
$mode = lc($mode); |
59
|
22
|
|
|
|
|
76
|
my $formatters = available_formatters($use_abbrev); |
60
|
22
|
|
|
|
|
53
|
my $fmt = $formatters->{$mode}; |
61
|
22
|
50
|
|
|
|
62
|
if (!$fmt) { |
62
|
0
|
|
|
|
|
0
|
$formatters = available_formatters(0); |
63
|
0
|
|
|
|
|
0
|
die "Format '$mode' unavailable. Available formats: ". |
64
|
|
|
|
|
|
|
join(", ", sort keys %$formatters)."\n"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
# Attempt to determine if format mode is in the base class. |
68
|
7
|
|
|
7
|
|
61
|
no strict 'refs'; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
1203
|
|
|
22
|
|
|
|
|
33
|
|
69
|
22
|
|
|
|
|
1694
|
eval "$fmt->new()"; |
70
|
22
|
100
|
66
|
|
|
199
|
if ( $@ and $@ =~ m/locate/ ) { |
|
|
50
|
|
|
|
|
|
71
|
2
|
|
|
2
|
|
247
|
eval "use $fmt"; |
|
2
|
|
|
|
|
1039
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
42
|
|
72
|
2
|
50
|
|
|
|
12
|
die "$@\n" if $@; |
73
|
|
|
|
|
|
|
} elsif ($@) { |
74
|
0
|
0
|
|
|
|
0
|
die "$@\n" if $@; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
22
|
|
|
|
|
206
|
return $fmt; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
package DBI::Format::Base; |
82
|
|
|
|
|
|
|
|
83
|
7
|
|
|
7
|
|
54
|
use DBI qw(:sql_types); |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
9443
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# DBI::Format::Foo objects are presently copies of the parent DBI::Shell |
86
|
|
|
|
|
|
|
# session hashref at the time of instantiation, and so are not aware of |
87
|
|
|
|
|
|
|
# `/option' updates to the parent thereafter. Check the ->{parent} member |
88
|
|
|
|
|
|
|
# for any session-specific /option values. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub new { |
91
|
42
|
|
|
42
|
|
97
|
my $class = shift; |
92
|
42
|
100
|
|
|
|
144
|
my $self = (@_ == 1) ? { %{$_[0]}, parent => $_[0] } : { @_ }; |
|
22
|
|
|
|
|
498
|
|
93
|
42
|
|
33
|
|
|
247
|
bless ($self, (ref($class) || $class)); |
94
|
42
|
|
|
|
|
322
|
$self; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Basic preparation for output, setting up 'fh', 'sth', 'rows' and possibly |
98
|
|
|
|
|
|
|
# 'sep' members. Also caches SQL type information and sets up BOOLEAN |
99
|
|
|
|
|
|
|
# formatting, if needed. |
100
|
|
|
|
|
|
|
sub header { |
101
|
53
|
|
|
53
|
|
157
|
my ($self, $sth, $fh, $sep) = @_; |
102
|
53
|
|
|
|
|
85
|
my $types; |
103
|
|
|
|
|
|
|
|
104
|
53
|
|
|
|
|
189
|
$self->{fh} = $self->setup_fh($fh); |
105
|
53
|
|
|
|
|
303
|
$self->{sth} = $sth; |
106
|
53
|
|
|
|
|
108
|
$self->{rows} = 0; |
107
|
53
|
100
|
|
|
|
173
|
$self->{sep} = $sep if defined $sep; |
108
|
|
|
|
|
|
|
|
109
|
53
|
|
|
|
|
306
|
$self->{__dbi_format_sql_types} = $types = $sth->{TYPE}; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Parent DBI::Shell session may have changed `/option bool_format' |
112
|
|
|
|
|
|
|
# since the last query we formatted, so update our internal bool |
113
|
|
|
|
|
|
|
# display data if needed. |
114
|
53
|
|
|
|
|
1590
|
for my $t (@$types) { |
115
|
259
|
50
|
|
|
|
597
|
next unless $t == SQL_BOOLEAN; |
116
|
|
|
|
|
|
|
$self->{__dbi_format_bool_alterns} = |
117
|
0
|
|
|
|
|
0
|
[ split(',', $self->{parent}->{bool_format}, 2) ]; |
118
|
0
|
|
|
|
|
0
|
last; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
53
|
|
|
|
|
121
|
$self; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# $fmt->encode_value( $value_reference, $sql_type ) |
125
|
|
|
|
|
|
|
# |
126
|
|
|
|
|
|
|
# Do not call directly. This method is called by DBI::Format::Base::row. |
127
|
|
|
|
|
|
|
# |
128
|
|
|
|
|
|
|
# Apply output encoding to a single, textual representation of a field |
129
|
|
|
|
|
|
|
# value. This method is called _after_ NULLs and BOOLEANs have been |
130
|
|
|
|
|
|
|
# stringified. |
131
|
|
|
|
|
|
|
# |
132
|
|
|
|
|
|
|
# Base implementation escapes \n, \t and \r and translates ASCII |
133
|
|
|
|
|
|
|
# non-printables without regard to $sql_type (SQL_NUMERIC, SQL_VARCHAR, |
134
|
|
|
|
|
|
|
# etc.). This is *not* ``safe'' for all terminals in all locales -- |
135
|
|
|
|
|
|
|
# the default is merely simple encoding. |
136
|
|
|
|
|
|
|
# |
137
|
|
|
|
|
|
|
# Subclasses may override to URI- or XML-encode certain data, for example. |
138
|
|
|
|
|
|
|
# |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub encode_value { |
141
|
2315
|
|
|
2315
|
|
3392
|
my ($self, $value_ref, $sql_type) = @_; |
142
|
|
|
|
|
|
|
|
143
|
2315
|
|
|
|
|
3401
|
for ($$value_ref) { |
144
|
2315
|
50
|
|
|
|
3686
|
last unless defined; |
145
|
2315
|
|
|
|
|
4113
|
s/\n/\\n/g; |
146
|
2315
|
|
|
|
|
3045
|
s/\t/\\t/g; |
147
|
2315
|
|
|
|
|
2811
|
s/\r/\\r/g; |
148
|
2315
|
|
|
|
|
4519
|
s/[\000-\037\177-\237]/./g; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# $fmt->row( $row_ref ) |
153
|
|
|
|
|
|
|
# |
154
|
|
|
|
|
|
|
# Basic preparation of row data, responsible for formatting NULLs and |
155
|
|
|
|
|
|
|
# BOOLEANs according to `/option' values, and calling encode_value() on |
156
|
|
|
|
|
|
|
# fields. As a convenience, also increments $fmt->{rows}. |
157
|
|
|
|
|
|
|
# |
158
|
|
|
|
|
|
|
# All subclasses should call this function from their overridden row() |
159
|
|
|
|
|
|
|
# methods. |
160
|
|
|
|
|
|
|
# |
161
|
|
|
|
|
|
|
# Note that row() modifies its argument in place, so $row_ref should be |
162
|
|
|
|
|
|
|
# a _copy_ of the (presumptively read-only) row from the active $sth. |
163
|
|
|
|
|
|
|
# |
164
|
|
|
|
|
|
|
sub row { |
165
|
509
|
|
|
509
|
|
876
|
my ($self, $row) = @_; |
166
|
|
|
|
|
|
|
|
167
|
509
|
|
|
|
|
734
|
my $i = 0; |
168
|
509
|
|
|
|
|
1035
|
for my $value (@$row) { |
169
|
2315
|
100
|
|
|
|
3837
|
unless (defined $value) { |
170
|
18
|
|
|
|
|
32
|
$value = $self->{parent}->{null_format}; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
2315
|
|
|
|
|
3353
|
my $sql_type = $self->{__dbi_format_sql_types}->[$i]; |
174
|
2315
|
50
|
|
|
|
4534
|
if ($sql_type == SQL_BOOLEAN) { |
175
|
0
|
0
|
|
|
|
0
|
$value = $self->{__dbi_format_bool_alterns}->[ $value ? 0 : 1 ]; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
2315
|
|
|
|
|
3814
|
$self->encode_value(\$value, $sql_type); |
179
|
|
|
|
|
|
|
} continue { |
180
|
2315
|
|
|
|
|
3510
|
$i++; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
509
|
|
|
|
|
770
|
$self->{rows}++; |
184
|
509
|
50
|
|
|
|
2078
|
return wantarray ? @$row : $row; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub setup_fh { |
188
|
53
|
|
|
53
|
|
118
|
my ($self, $fh) = @_; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# This method has grown confused as to what it's trying to do and why |
191
|
|
|
|
|
|
|
# Partly because this module was written in pre-perl5.3 days |
192
|
|
|
|
|
|
|
# the code in other methods originally did: $fh->print(...) |
193
|
|
|
|
|
|
|
# because C didn't work reliably as a method call. |
194
|
|
|
|
|
|
|
# Now the code uses C some of this may no longer be |
195
|
|
|
|
|
|
|
# required. It's important that things like IO::Scalar handles work. |
196
|
|
|
|
|
|
|
|
197
|
53
|
0
|
33
|
|
|
174
|
return $self->{fh} if !$fh && $self->{fh}; |
198
|
|
|
|
|
|
|
|
199
|
53
|
|
50
|
|
|
136
|
$fh ||= \*STDOUT; |
200
|
|
|
|
|
|
|
|
201
|
53
|
100
|
|
|
|
364
|
return $fh if ref($fh) =~ m/GLOB/; |
202
|
|
|
|
|
|
|
|
203
|
1
|
50
|
|
|
|
14
|
unless (UNIVERSAL::can($fh,'print')) { # not blessed |
204
|
0
|
|
|
|
|
0
|
require FileHandle; |
205
|
0
|
|
|
|
|
0
|
bless $fh => "FileHandle"; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
1
|
|
|
|
|
4
|
return $fh; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub trailer { |
213
|
50
|
|
|
50
|
|
127
|
my($self) = @_; |
214
|
50
|
|
|
|
|
131
|
my $fh = delete $self->{'fh'}; |
215
|
50
|
|
|
|
|
115
|
my $sth = delete $self->{'sth'}; |
216
|
50
|
|
|
|
|
117
|
my $rows = delete $self->{'rows'}; |
217
|
50
|
|
|
|
|
1029
|
print $fh ("[$rows rows of $sth->{NUM_OF_FIELDS} fields returned]\n"); |
218
|
50
|
|
|
|
|
376
|
delete $self->{'sep'}; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub _determine_width { |
222
|
19
|
|
|
19
|
|
296
|
my($self , $type, $precision) = @_; |
223
|
|
|
|
|
|
|
|
224
|
19
|
50
|
66
|
|
|
227
|
my $width = |
|
|
50
|
33
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
225
|
|
|
|
|
|
|
(!defined($type)) ? 0 : # Is type defined? |
226
|
|
|
|
|
|
|
($type == SQL_DATE) ? 8 : # Is type a Date? |
227
|
|
|
|
|
|
|
($type == SQL_INTEGER # Is type an Integer? |
228
|
|
|
|
|
|
|
and defined $precision |
229
|
|
|
|
|
|
|
and $precision > 15 ) ? 10 : |
230
|
|
|
|
|
|
|
($type == SQL_NUMERIC # Is type a Numeric? |
231
|
|
|
|
|
|
|
and defined $precision |
232
|
|
|
|
|
|
|
and $precision > 15 ) ? 10 : |
233
|
|
|
|
|
|
|
defined($precision) ? $precision: 0; # Default 0 |
234
|
|
|
|
|
|
|
|
235
|
19
|
|
|
|
|
51
|
return $width; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
package DBI::Format::Neat; |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
@DBI::Format::Neat::ISA = qw(DBI::Format::Base); |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub header { |
244
|
26
|
|
|
26
|
|
73
|
my ($self, $sth, $fh, $sep) = @_; |
245
|
26
|
|
|
|
|
142
|
$self->SUPER::header($sth, $fh, $sep); |
246
|
26
|
|
|
|
|
41
|
print {$self->{fh}} (join($self->{sep}, @{$sth->{'NAME'}}), "\n"); |
|
26
|
|
|
|
|
95
|
|
|
26
|
|
|
|
|
1256
|
|
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub row { |
250
|
249
|
|
|
249
|
|
424
|
my($self, $rowref) = @_; |
251
|
249
|
|
|
|
|
783
|
my @row = $self->SUPER::row([@$rowref]); |
252
|
249
|
|
|
|
|
590
|
my $fh = $self->{'fh'}; |
253
|
249
|
|
|
|
|
801
|
print $fh (DBI::neat_list(\@row, 9999, $self->{sep}),"\n"); |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
package DBI::Format::Box; |
259
|
|
|
|
|
|
|
|
260
|
7
|
|
|
7
|
|
59
|
use DBI qw(:sql_types); |
|
7
|
|
|
|
|
24
|
|
|
7
|
|
|
|
|
6660
|
|
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
@DBI::Format::Box::ISA = qw(DBI::Format::Base); |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub header { |
265
|
1
|
|
|
1
|
|
4
|
my($self, $sth, $fh, $sep) = @_; |
266
|
1
|
|
|
|
|
10
|
$self->SUPER::header($sth, $fh, $sep); |
267
|
1
|
|
|
|
|
6
|
my $types = $sth->{'TYPE'}; |
268
|
1
|
|
|
|
|
14
|
my @right_justify; |
269
|
|
|
|
|
|
|
my @widths; |
270
|
1
|
|
|
|
|
5
|
my $names = $sth->{'NAME'}; |
271
|
1
|
|
|
|
|
3
|
my $type; |
272
|
1
|
|
|
|
|
7
|
for (my $i = 0; $i < $sth->{'NUM_OF_FIELDS'}; $i++) { |
273
|
14
|
50
|
|
|
|
37
|
push(@widths, defined($names->[$i]) ? length($names->[$i]) : 0); |
274
|
14
|
|
|
|
|
22
|
$type = $types->[$i]; |
275
|
14
|
|
66
|
|
|
182
|
push(@right_justify, |
276
|
|
|
|
|
|
|
(defined($type) and ($type == SQL_NUMERIC || |
277
|
|
|
|
|
|
|
$type == SQL_DECIMAL || |
278
|
|
|
|
|
|
|
$type == SQL_INTEGER || |
279
|
|
|
|
|
|
|
$type == SQL_SMALLINT || |
280
|
|
|
|
|
|
|
$type == SQL_FLOAT || |
281
|
|
|
|
|
|
|
$type == SQL_REAL || |
282
|
|
|
|
|
|
|
$type == SQL_TINYINT)) |
283
|
|
|
|
|
|
|
); |
284
|
|
|
|
|
|
|
} |
285
|
1
|
|
|
|
|
4
|
$self->{'widths'} = \@widths; |
286
|
1
|
|
|
|
|
5
|
$self->{'right_justify'} = \@right_justify; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
sub row { |
291
|
10
|
|
|
10
|
|
19
|
my($self, $orig_row) = @_; |
292
|
10
|
|
|
|
|
14
|
my $i = 0; |
293
|
10
|
|
|
|
|
12
|
my $col; |
294
|
10
|
|
|
|
|
16
|
my $widths = $self->{'widths'}; |
295
|
10
|
|
|
|
|
38
|
my @row = $self->SUPER::row([@$orig_row]); # don't mess with the original row |
296
|
10
|
|
|
|
|
34
|
for (@row) { |
297
|
140
|
100
|
|
|
|
213
|
if (length > $widths->[$i]) { |
298
|
12
|
|
|
|
|
16
|
$widths->[$i] = length; |
299
|
|
|
|
|
|
|
} |
300
|
140
|
|
|
|
|
175
|
++$i; |
301
|
|
|
|
|
|
|
} |
302
|
10
|
|
|
|
|
15
|
push @{$self->{data}}, \@row; |
|
10
|
|
|
|
|
36
|
|
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
sub trailer { |
307
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
308
|
1
|
|
|
|
|
4
|
my $widths = delete $self->{'widths'}; |
309
|
1
|
|
|
|
|
2
|
my $right_justify = delete $self->{'right_justify'}; |
310
|
1
|
|
|
|
|
12
|
my $sth = $self->{'sth'}; |
311
|
1
|
|
|
|
|
3
|
my $data = $self->{'data'}; |
312
|
1
|
|
|
|
|
3
|
$self->{'rows'} = @$data; |
313
|
|
|
|
|
|
|
|
314
|
1
|
|
|
|
|
2
|
my $format_sep = '+'; |
315
|
1
|
|
|
|
|
2
|
my $format_names = '|'; |
316
|
1
|
|
|
|
|
2
|
my $format_rows = '|'; |
317
|
1
|
|
|
|
|
11
|
for (my $i = 0; $i < $sth->{'NUM_OF_FIELDS'}; $i++) { |
318
|
14
|
|
|
|
|
34
|
$format_sep .= ('-' x $widths->[$i]) . '+'; |
319
|
14
|
|
|
|
|
34
|
$format_names .= sprintf("%%-%ds|", $widths->[$i]); |
320
|
14
|
100
|
|
|
|
77
|
$format_rows .= sprintf("%%" |
321
|
|
|
|
|
|
|
. ($right_justify->[$i] ? "" : "-") . "%ds|", |
322
|
|
|
|
|
|
|
$widths->[$i]); |
323
|
|
|
|
|
|
|
} |
324
|
1
|
|
|
|
|
3
|
$format_sep .= "\n"; |
325
|
1
|
|
|
|
|
1
|
$format_names .= "\n"; |
326
|
1
|
|
|
|
|
2
|
$format_rows .= "\n"; |
327
|
|
|
|
|
|
|
|
328
|
1
|
|
|
|
|
2
|
my $fh = $self->{'fh'}; |
329
|
1
|
|
|
|
|
47
|
print $fh ($format_sep); |
330
|
1
|
|
|
|
|
5
|
print $fh (sprintf($format_names, @{$sth->{'NAME'}})); |
|
1
|
|
|
|
|
22
|
|
331
|
1
|
|
|
|
|
6
|
foreach my $row (@$data) { |
332
|
10
|
|
|
|
|
73
|
print $fh ($format_sep); |
333
|
10
|
|
|
|
|
104
|
print $fh (sprintf($format_rows, @$row)); |
334
|
|
|
|
|
|
|
} |
335
|
1
|
|
|
|
|
8
|
print $fh ($format_sep); |
336
|
|
|
|
|
|
|
|
337
|
1
|
|
|
|
|
9
|
$self->SUPER::trailer(@_); |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
package DBI::Format::PartBox; |
341
|
|
|
|
|
|
|
|
342
|
7
|
|
|
7
|
|
70
|
use DBI qw(:sql_types); |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
14824
|
|
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
@DBI::Format::PartBox::ISA = qw(DBI::Format::Base); |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
sub header { |
347
|
0
|
|
|
0
|
|
0
|
my ($self, $sth, $fh, $sep) = @_; |
348
|
0
|
|
|
|
|
0
|
$self->SUPER::header($sth, $fh, $sep); |
349
|
0
|
|
|
|
|
0
|
my $types = $sth->{'TYPE'}; |
350
|
0
|
|
|
|
|
0
|
my @right_justify; |
351
|
|
|
|
|
|
|
my @widths; |
352
|
0
|
|
|
|
|
0
|
my $names = $sth->{'NAME'}; |
353
|
0
|
|
|
|
|
0
|
my $type; |
354
|
0
|
|
|
|
|
0
|
for (my $i = 0; $i < $sth->{'NUM_OF_FIELDS'}; $i++) { |
355
|
0
|
0
|
|
|
|
0
|
push(@widths, defined($names->[$i]) ? length($names->[$i]) : 0); |
356
|
0
|
|
|
|
|
0
|
$type = $types->[$i]; |
357
|
0
|
|
0
|
|
|
0
|
push(@right_justify, |
358
|
|
|
|
|
|
|
($type == SQL_NUMERIC || |
359
|
|
|
|
|
|
|
$type == SQL_DECIMAL || |
360
|
|
|
|
|
|
|
$type == SQL_INTEGER || |
361
|
|
|
|
|
|
|
$type == SQL_SMALLINT || |
362
|
|
|
|
|
|
|
$type == SQL_FLOAT || |
363
|
|
|
|
|
|
|
$type == SQL_REAL || |
364
|
|
|
|
|
|
|
$type == SQL_TINYINT)); |
365
|
|
|
|
|
|
|
} |
366
|
0
|
|
|
|
|
0
|
$self->{'widths'} = \@widths; |
367
|
0
|
|
|
|
|
0
|
$self->{'right_justify'} = \@right_justify; |
368
|
|
|
|
|
|
|
} |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
sub row { |
372
|
0
|
|
|
0
|
|
0
|
my($self, $orig_row) = @_; |
373
|
0
|
|
|
|
|
0
|
my $i = 0; |
374
|
0
|
|
|
|
|
0
|
my $col; |
375
|
0
|
|
|
|
|
0
|
my $widths = $self->{'widths'}; |
376
|
0
|
|
|
|
|
0
|
my @row = $self->SUPER::row([@$orig_row]); # don't mess with the original row |
377
|
0
|
|
|
|
|
0
|
for (@row) { |
378
|
0
|
0
|
|
|
|
0
|
if (length > $widths->[$i]) { |
379
|
0
|
|
|
|
|
0
|
$widths->[$i] = length; |
380
|
|
|
|
|
|
|
} |
381
|
0
|
|
|
|
|
0
|
++$i; |
382
|
|
|
|
|
|
|
} |
383
|
0
|
|
|
|
|
0
|
push @{$self->{data}}, \@row; |
|
0
|
|
|
|
|
0
|
|
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
sub trailer { |
388
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
389
|
0
|
|
|
|
|
0
|
my $widths = delete $self->{'widths'}; |
390
|
0
|
|
|
|
|
0
|
my $right_justify = delete $self->{'right_justify'}; |
391
|
0
|
|
|
|
|
0
|
my $sth = $self->{'sth'}; |
392
|
0
|
|
|
|
|
0
|
my $data = $self->{'data'}; |
393
|
0
|
|
|
|
|
0
|
$self->{'rows'} = @$data; |
394
|
|
|
|
|
|
|
|
395
|
0
|
|
|
|
|
0
|
my $format_sep = '+'; |
396
|
0
|
|
|
|
|
0
|
my $format_names = '|'; |
397
|
0
|
|
|
|
|
0
|
my $format_rows = '|'; |
398
|
0
|
|
|
|
|
0
|
for (my $i = 0; $i < $sth->{'NUM_OF_FIELDS'}; $i++) { |
399
|
0
|
|
|
|
|
0
|
$format_sep .= ('-' x $widths->[$i]) . '+'; |
400
|
0
|
|
|
|
|
0
|
$format_names .= sprintf("%%-%ds|", $widths->[$i]); |
401
|
0
|
0
|
|
|
|
0
|
$format_rows .= sprintf("%%" |
402
|
|
|
|
|
|
|
. ($right_justify->[$i] ? "" : "-") . "%ds|", |
403
|
|
|
|
|
|
|
$widths->[$i]); |
404
|
|
|
|
|
|
|
} |
405
|
0
|
|
|
|
|
0
|
$format_sep .= "\n"; |
406
|
0
|
|
|
|
|
0
|
$format_names .= "\n"; |
407
|
0
|
|
|
|
|
0
|
$format_rows .= "\n"; |
408
|
|
|
|
|
|
|
|
409
|
0
|
|
|
|
|
0
|
my $fh = $self->{'fh'}; |
410
|
0
|
|
|
|
|
0
|
print $fh ($format_sep); |
411
|
0
|
|
|
|
|
0
|
print $fh (sprintf($format_names, @{$sth->{'NAME'}})); |
|
0
|
|
|
|
|
0
|
|
412
|
0
|
|
|
|
|
0
|
print $fh ($format_sep); |
413
|
0
|
|
|
|
|
0
|
foreach my $row (@$data) { |
414
|
|
|
|
|
|
|
# print $fh ($format_sep); |
415
|
0
|
|
|
|
|
0
|
print $fh (sprintf($format_rows, @$row)); |
416
|
|
|
|
|
|
|
} |
417
|
0
|
|
|
|
|
0
|
print $fh ($format_sep); |
418
|
|
|
|
|
|
|
|
419
|
0
|
|
|
|
|
0
|
$self->SUPER::trailer(@_); |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
package DBI::Format::Raw; |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
@DBI::Format::Raw::ISA = qw(DBI::Format::Base); |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
sub header { |
427
|
1
|
|
|
1
|
|
5
|
my ($self, $sth, $fh, $sep) = @_; |
428
|
1
|
|
|
|
|
23
|
$self->SUPER::header($sth, $fh, $sep); |
429
|
1
|
|
|
|
|
1
|
print {$self->{fh}} (join($self->{sep}, @{$sth->{'NAME'}}), "\n"); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
430
|
|
|
|
|
|
|
} |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
sub row { |
433
|
10
|
|
|
10
|
|
18
|
my($self, $rowref) = @_; |
434
|
10
|
|
|
|
|
42
|
local $^W = 0; |
435
|
10
|
|
|
|
|
23
|
my @row = @$rowref; |
436
|
10
|
|
|
|
|
17
|
my $fh = $self->{'fh'}; |
437
|
10
|
|
|
|
|
307
|
print $fh (join($self->{sep}, @row), "\n"); |
438
|
|
|
|
|
|
|
} |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
package DBI::Format::String; |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
@DBI::Format::String::ISA = qw(DBI::Format::Base); |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
sub header { |
445
|
1
|
|
|
1
|
|
4
|
my ($self, $sth, $fh, $sep) = @_; |
446
|
1
|
|
|
|
|
10
|
$self->SUPER::header($sth, $fh, $sep); |
447
|
1
|
|
|
|
|
5
|
my $types = $sth->{'TYPE'}; |
448
|
1
|
|
|
|
|
14
|
my @right_justify; |
449
|
|
|
|
|
|
|
my @widths; |
450
|
1
|
|
|
|
|
5
|
my $names = $sth->{'NAME'}; |
451
|
1
|
|
|
|
|
3
|
my $type; |
452
|
1
|
|
|
|
|
8
|
for (my $i = 0; $i < $sth->{'NUM_OF_FIELDS'}; $i++) { |
453
|
14
|
|
|
|
|
40
|
$type = $types->[$i]; |
454
|
|
|
|
|
|
|
push(@widths, $self->_determine_width( |
455
|
14
|
|
|
|
|
64
|
$type, $sth->{PRECISION}->[$i] )); |
456
|
|
|
|
|
|
|
|
457
|
14
|
|
66
|
|
|
122
|
push(@right_justify, |
458
|
|
|
|
|
|
|
(defined($type) and ($type == DBI::SQL_NUMERIC() || |
459
|
|
|
|
|
|
|
$type == DBI::SQL_DECIMAL() || |
460
|
|
|
|
|
|
|
$type == DBI::SQL_INTEGER() || |
461
|
|
|
|
|
|
|
$type == DBI::SQL_SMALLINT() || |
462
|
|
|
|
|
|
|
$type == DBI::SQL_FLOAT() || |
463
|
|
|
|
|
|
|
$type == DBI::SQL_REAL() || |
464
|
|
|
|
|
|
|
$type == DBI::SQL_TINYINT())) |
465
|
|
|
|
|
|
|
); |
466
|
14
|
|
|
|
|
20
|
my $format_names; |
467
|
14
|
|
|
|
|
54
|
$format_names .= sprintf("%%-%ds ", $widths[$i]); |
468
|
14
|
|
|
|
|
17
|
print {$self->{fh}} (sprintf($format_names, $names->[$i])); |
|
14
|
|
|
|
|
520
|
|
469
|
|
|
|
|
|
|
} |
470
|
1
|
|
|
|
|
5
|
$self->{'widths'} = \@widths; |
471
|
1
|
|
|
|
|
3
|
$self->{'right_justify'} = \@right_justify; |
472
|
1
|
|
|
|
|
2
|
print {$self->{fh}} "\n"; |
|
1
|
|
|
|
|
14
|
|
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
sub row { |
478
|
10
|
|
|
10
|
|
18
|
my($self, $orig_row) = @_; |
479
|
10
|
|
|
|
|
17
|
my $i = 0; |
480
|
10
|
|
|
|
|
14
|
my $col; |
481
|
10
|
|
|
|
|
17
|
my $widths = $self->{'widths'}; |
482
|
10
|
|
|
|
|
13
|
my $right_justify = $self->{'right_justify'}; |
483
|
10
|
|
|
|
|
37
|
my @row = $self->SUPER::row([@$orig_row]); # don't mess with the original row |
484
|
|
|
|
|
|
|
|
485
|
10
|
|
|
|
|
30
|
my $sth = $self->{'sth'}; |
486
|
10
|
|
|
|
|
14
|
my $format_rows = ' '; |
487
|
10
|
|
|
|
|
73
|
for (my $i = 0; $i < $sth->{'NUM_OF_FIELDS'}; $i++) { |
488
|
140
|
100
|
|
|
|
792
|
$format_rows .= sprintf("%%" |
489
|
|
|
|
|
|
|
. ($right_justify->[$i] ? "" : "-") . "%ds ", |
490
|
|
|
|
|
|
|
$widths->[$i]); |
491
|
|
|
|
|
|
|
} |
492
|
10
|
|
|
|
|
23
|
$format_rows .= "\n"; |
493
|
|
|
|
|
|
|
|
494
|
10
|
|
|
|
|
16
|
my $fh = $self->{'fh'}; |
495
|
10
|
|
|
|
|
428
|
print $fh (sprintf($format_rows, @row)); |
496
|
|
|
|
|
|
|
} |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
sub trailer { |
500
|
1
|
|
|
1
|
|
5
|
my $self = shift; |
501
|
1
|
|
|
|
|
3
|
my $widths = delete $self->{'widths'}; |
502
|
1
|
|
|
|
|
3
|
my $right_justify = delete $self->{'right_justify'}; |
503
|
1
|
|
|
|
|
7
|
$self->SUPER::trailer(@_); |
504
|
|
|
|
|
|
|
} |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
package DBI::Format::HTML; |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
@DBI::Format::HTML::ISA = qw(DBI::Format::Base); |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
sub header { |
511
|
1
|
|
|
1
|
|
8
|
my($self, $sth, $fh) = @_; |
512
|
1
|
|
|
|
|
10
|
$self->SUPER::header($sth, $fh); |
513
|
1
|
|
|
|
|
3
|
$self->{'data'} = []; |
514
|
1
|
|
|
|
|
5
|
my $types = $sth->{'TYPE'}; |
515
|
1
|
|
|
|
|
13
|
my @right_justify; |
516
|
|
|
|
|
|
|
my @widths; |
517
|
1
|
|
|
|
|
4
|
my $names = $sth->{'NAME'}; |
518
|
1
|
|
|
|
|
2
|
my $type; |
519
|
1
|
|
|
|
|
9
|
for (my $i = 0; $i < $sth->{'NUM_OF_FIELDS'}; $i++) { |
520
|
14
|
50
|
|
|
|
40
|
push(@widths, defined($names->[$i]) ? length($names->[$i]) : 0); |
521
|
14
|
|
|
|
|
20
|
$type = $types->[$i]; |
522
|
14
|
|
66
|
|
|
178
|
push(@right_justify, |
523
|
|
|
|
|
|
|
(defined $type and ($type == DBI::SQL_NUMERIC() || |
524
|
|
|
|
|
|
|
$type == DBI::SQL_DECIMAL() || |
525
|
|
|
|
|
|
|
$type == DBI::SQL_INTEGER() || |
526
|
|
|
|
|
|
|
$type == DBI::SQL_SMALLINT() || |
527
|
|
|
|
|
|
|
$type == DBI::SQL_FLOAT() || |
528
|
|
|
|
|
|
|
$type == DBI::SQL_REAL() || |
529
|
|
|
|
|
|
|
$type == DBI::SQL_TINYINT())) |
530
|
|
|
|
|
|
|
); |
531
|
|
|
|
|
|
|
} |
532
|
1
|
|
|
|
|
5
|
$self->{'widths'} = \@widths; |
533
|
1
|
|
|
|
|
4
|
$self->{'right_justify'} = \@right_justify; |
534
|
|
|
|
|
|
|
} |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
sub row { |
538
|
10
|
|
|
10
|
|
20
|
my($self, $orig_row) = @_; |
539
|
10
|
|
|
|
|
15
|
my $i = 0; |
540
|
10
|
|
|
|
|
12
|
my $col; |
541
|
10
|
|
|
|
|
16
|
my $widths = $self->{'widths'}; |
542
|
10
|
|
|
|
|
37
|
my @row = $self->SUPER::row([@$orig_row]); # don't mess with the original row |
543
|
10
|
|
|
|
|
27
|
for (@row) { |
544
|
140
|
100
|
|
|
|
228
|
if (length($_) > $widths->[$i]) { |
545
|
12
|
|
|
|
|
17
|
$widths->[$i] = length($_); |
546
|
|
|
|
|
|
|
} |
547
|
140
|
|
|
|
|
162
|
++$i; |
548
|
|
|
|
|
|
|
} |
549
|
10
|
|
|
|
|
12
|
push @{$self->{data}}, \@row; |
|
10
|
|
|
|
|
36
|
|
550
|
|
|
|
|
|
|
} |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
sub trailer { |
554
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
555
|
1
|
|
|
|
|
4
|
my $widths = delete $self->{'widths'}; |
556
|
1
|
|
|
|
|
2
|
my $right_justify = delete $self->{'right_justify'}; |
557
|
1
|
|
|
|
|
3
|
my $sth = $self->{'sth'}; |
558
|
1
|
|
|
|
|
3
|
my $data = $self->{'data'}; |
559
|
1
|
|
|
|
|
3
|
$self->{'rows'} = @$data; |
560
|
|
|
|
|
|
|
|
561
|
1
|
|
|
|
|
4
|
my $format_sep = '+'; |
562
|
1
|
|
|
|
|
4
|
my $format_names = ' |
';
563
|
1
|
|
|
|
|
1
|
my $format_rows = ' |
';
564
|
1
|
|
|
|
|
11
|
for (my $i = 0; $i < $sth->{'NUM_OF_FIELDS'}; $i++) { |
565
|
14
|
|
|
|
|
38
|
$format_names .= sprintf(" | %%-%ds | ", $widths->[$i]);
566
|
14
|
100
|
|
|
|
83
|
$format_rows .= sprintf(" | %%" |
567
|
|
|
|
|
|
|
. ($right_justify->[$i] ? "" : "-") . "%ds | ",
568
|
|
|
|
|
|
|
$widths->[$i]); |
569
|
|
|
|
|
|
|
} |
570
|
1
|
|
|
|
|
3
|
$format_sep .= "\n"; |
571
|
1
|
|
|
|
|
2
|
$format_names .= " |
\n";
572
|
1
|
|
|
|
|
2
|
$format_rows .= " |
\n";
573
|
|
|
|
|
|
|
|
574
|
1
|
|
|
|
|
2
|
my $fh = $self->{'fh'}; |
575
|
1
|
|
|
|
|
38
|
print $fh("\n");
576
|
1
|
|
|
|
|
5
|
print $fh(sprintf($format_names, @{$sth->{'NAME'}})); |
|
1
|
|
|
|
|
23
|
|
577
|
1
|
|
|
|
|
11
|
foreach my $row (@$data) { |
578
|
10
|
|
|
|
|
116
|
print $fh (sprintf($format_rows, @$row)); |
579
|
|
|
|
|
|
|
} |
580
|
1
|
|
|
|
|
10
|
print $fh (" | \n"); |
581
|
|
|
|
|
|
|
|
582
|
1
|
|
|
|
|
9
|
$self->SUPER::trailer(@_); |
583
|
|
|
|
|
|
|
} |
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
1; |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
=head1 NAME |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
DBI::Format - A package for displaying result tables |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
=head1 SYNOPSIS |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
# create a new result object |
595
|
|
|
|
|
|
|
$r = DBI::Format->new('var1' => 'val1', ...); |
596
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
# Prepare it for output by creating a header |
598
|
|
|
|
|
|
|
$r->header($sth, $fh); |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
# In a loop, display rows |
601
|
|
|
|
|
|
|
while ($ref = $sth->fetchrow_arrayref()) { |
602
|
|
|
|
|
|
|
$r->row($ref); |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
# Finally create a trailer |
606
|
|
|
|
|
|
|
$r->trailer(); |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
=head1 DESCRIPTION |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
THIS PACKAGE IS STILL VERY EXPERIMENTAL. THINGS WILL CHANGE. |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
This package is used for making the output of DBI::Shell configurable. |
614
|
|
|
|
|
|
|
The idea is to derive a subclass for any kind of output table you might |
615
|
|
|
|
|
|
|
create. Examples are |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
=over 8 |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
=item * |
620
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
a very simple output format as offered by DBI::neat_list(). |
622
|
|
|
|
|
|
|
L<"AVAILABLE SUBCLASSES">. |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
=item * |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
a box format, as offered by the Data::ShowTable module. |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
=item * |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
HTML format, as used in CGI binaries |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
=item * |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
postscript, to be piped into lpr or something similar |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
=back |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
In the future the package should also support interactive methods, for |
639
|
|
|
|
|
|
|
example tab completion. |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
These are the available methods: |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
=over 8 |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
=item new(@attr) |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
=item new(\%attr) |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
(Class method) This is the constructor. You'd rather call a subclass |
650
|
|
|
|
|
|
|
constructor. The construcor is accepting either a list of key/value |
651
|
|
|
|
|
|
|
pairs or a hash ref. |
652
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
=item header($sth, $fh) |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
(Instance method) This is called when a new result table should be |
656
|
|
|
|
|
|
|
created to display the results of the statement handle B<$sth>. The |
657
|
|
|
|
|
|
|
(optional) argument B<$fh> is an IO handle (or any object supporting |
658
|
|
|
|
|
|
|
a I method), usually you use an IO::Wrap object for STDIN. |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
The method will query the B<$sth> for its I, I, |
661
|
|
|
|
|
|
|
I, I and I attributes and typically print a |
662
|
|
|
|
|
|
|
header. In general you should not assume that B<$sth> is indeed a DBI |
663
|
|
|
|
|
|
|
statement handle and better treat it as a hash ref with the above |
664
|
|
|
|
|
|
|
attributes. |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
=item row($ref) |
667
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
(Instance method) Prints the contents of the array ref B<$ref>. Usually |
669
|
|
|
|
|
|
|
you obtain this array ref by calling B<$sth-Efetchrow_arrayref()>. |
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
=item trailer |
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
(Instance method) Once you have passed all result rows to the result |
674
|
|
|
|
|
|
|
package, you should call the I method. This method can, for |
675
|
|
|
|
|
|
|
example print the number of result rows. |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
=back |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
=head1 AVAILABLE SUBCLASSES |
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
First of all, you can use the DBI::Format package itself: It's |
683
|
|
|
|
|
|
|
not an abstract base class, but a very simple default using |
684
|
|
|
|
|
|
|
DBI::neat_list(). |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
=head2 Ascii boxes |
688
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
This subclass is using the I mode of the I module |
690
|
|
|
|
|
|
|
internally. L. |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
=head2 Raw |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
Row is written without formating. Columns returned in comma or user defined |
695
|
|
|
|
|
|
|
separated list. |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
=head2 String |
698
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
Row is written using a string format. Future releases will include th ability |
700
|
|
|
|
|
|
|
set the string format. |
701
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
=head1 AUTHOR AND COPYRIGHT |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
This module is Copyright (c) 1997, 1998 |
706
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
Jochen Wiedmann |
708
|
|
|
|
|
|
|
Am Eisteich 9 |
709
|
|
|
|
|
|
|
72555 Metzingen |
710
|
|
|
|
|
|
|
Germany |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
Email: joe@ispsoft.de |
713
|
|
|
|
|
|
|
Phone: +49 7123 14887 |
714
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
The DBD::Proxy module is free software; you can redistribute it and/or |
716
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
=head1 SEE ALSO |
720
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
L, L, L |