blib/lib/DBI/Format/SQLMinus.pm

filter: Statementstmt 76.0% 146 / 192 Branchbran 58.5% 48 / 82 Conditioncond 19.0% 16 / 84 MC/DCmcdc 13.9% 6 / 43 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 4 totaltotal 54.1% 224 / 414 CC 73 SCAR 46.1
CC
73
Cov
59%
header
116.3
row
107.7
re_headers
56.0
CRAP 100.3
« blib/lib/DBI/Shell/Completion.pm ↑ Summary blib/lib/DBI/Shell/Spool.pm »
1 # -*- perl -*-
2 # vim:ts=4:sw=4:aw:ai:
3 #
4 # DBI::Format::SQLMinus - a package for displaying result tables
5 #
6 # Copyright (c) 2001, 2002 Thomas A. Lowery
7 #
8 # The DBI::Shell::SQLMinus module is free software; you can redistribute
9 # it and/or modify it under the same terms as Perl itself.
10 #
11  
12 #
13 # The "meat" of this format comes from interaction with the sqlminus
14 # plugin module.
15 #
16  
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 package DBI::Format::SQLMinus;
20  
21 1 our $VERSION = '11.98'; # VERSION
22  
23 1 @DBI::Format::SQLMinus::ISA = qw(DBI::Format::Base);
24  
25 1 ▶use Text::Abbrev;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Text::Reform qw(form break_with);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 20 ▶sub header {
Subroutine header: called CC=47 SCAR=47.6
Pod undocumented
31 20 my ($self, $sth, $fh, $sep) = @_;
32 20 $self->SUPER::header($sth, $fh, $sep);
33 20 $self->{'data'} = [];
34 20 $self->{'formats'} = [];
35 #
36 # determine default behavior based either on the setting in
37 # sqlminus, or pre-defined defaults. Without sqlminus loaded,
38 # these defaults setting are static. Using the sqlminus "set"
39 # command to change setting.
40 #
41  
42 20 my ($breaks, $set, $column_format, $column_header_format, $sqlminus);
43  
44 20 ▶ if ( exists $self->{plugin}->{sqlminus} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'plugin'}{'sqlminus'}) { } 20 0 20
45  
46 # sqlminus plugin installed.
47 20 $sqlminus = $self->{plugin}->{sqlminus};
48  
49 20 $set = $sqlminus->{set_current};
50 20 $column_format = $sqlminus->{column_format};
51 $column_header_format =
52 20 $sqlminus->{column_header_format};
53 20 $breaks = $sqlminus->{break_current};
54 } else {
55 0 warn 'sqlminus plugin not installed\n';
56 0 $sqlminus = undef;
57 0 $set = {};
58 0 $column_format = {};
59 0 $column_header_format = {};
60 }
61  
62 20 $self->{feedback} = $set->{feedback};
63 20 $self->{limit} = $set->{limit};
64 20 $self->{pagesize} = $set->{pagesize};
65 20 $self->{recsepchar} = $set->{recsepchar};
66 20 $self->{recsep} = $set->{recsep};
67  
68 20 $self->{pagefeed} = undef;
69 20 $self->{pagelen} = 66;
70 20 $self->{pagenum} = 0;
71  
72 # $self->{breaks};
73  
74 20 my $types = $sth->{'TYPE'};
75 20 my @right_justify;
76 my @widths;
77 20 my @heading;
78 20 my @display;
79 20 my $names = $sth->{'NAME'};
80 20 my $names_lc = $sth->{'NAME_lc'};
81 20 my $type;
82 my $format_row;
83 20 my @ul;
84 20 my @fmtfunc;
85 20 my @commify;
86  
87 20 my $attribs = {
88 name => undef
89 ,name_lc => undef
90 ,precision => undef
91 ,scale => undef
92 ,len => undef
93 ,commify => undef
94 ,fmtfunc => undef
95 ,justify => undef
96 ,type => undef
97 ,format => undef
98 ,display => undef
99 ,heading => undef
100 };
101  
102 20 my @columns = ();
103  
104 20 ▶ for (my $i = 0; $i < $sth->{'NUM_OF_FIELDS'}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $sth->{"NUM_OF_FIELDS"}) 32 20 52
105  
106  
107 32 my $myattribs = ();
108 32 $myattribs->{$_} = undef foreach ( sort keys %$attribs );
109  
110 32 my ($format_names, $heading, $width, $type, $justify);
111 # Default, left justify everything.
112 32 $justify = '<';
113 32 $myattribs->{justify} = q{<};
114  
115 32 push(@display, 1);
116  
117 32 $myattribs->{display}++;
118  
119 32 $myattribs->{name} = $names->[$i];
120 32 $myattribs->{name_lc} = $names_lc->[$i];
121  
122 32 my $n_lc = $names_lc->[$i];
123 # Determine if a break point exists.
124 32 ▶ if ( exists $breaks->{$n_lc} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $breaks->{$n_lc}) 0 32 32
125 0 print "Column " . $n_lc . " has a break point\n";
126 0 push @{$self->{breaks}->{order_of}}, $n_lc;
127 0 for (keys %{$breaks->{$n_lc}}) {
128 $self->{breaks}->{$n_lc}->{$_} =
129 0 $breaks->{$n_lc}->{$_};
130 }
131  
132 0 $self->{breaks}->{$n_lc}->{last_break_point} = undef;
133 }
134  
135 32 ▶ if ( exists $column_format->{$names_lc->[$i]} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$column_format{$names_lc->[$i]}) 28 4 32
136 28 my $cf = $column_format->{$names_lc->[$i]};
137  
138 # Determine if the column formating is on or off.
139 28 ▶ if ( exists $cf->{on} and $cf->{on} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cf->{"on"} and $cf->{"on"}) 27 1 28
Condition66%2/3
exists $cf->{"on"} and $cf->{"on"}
!ll&&!rl&&r
0127
MC/DC50%1/2
exists $cf->{"on"} and $cf->{"on"}
exists $cf->{"on"} $cf->{"on"}
Truth table66%2/3
A and B
A= exists $cf->{"on"}B= $cf->{"on"}
ABresult
0X0
100
111
140  
141 # Determine if this column is printed.
142 # If this column is set to noprint, then skip.
143 27 ▶ if (exists $cf->{noprint} and $cf->{noprint}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cf->{"noprint"} and $cf->{"noprint"}) 2 25 27
Condition66%2/3
exists $cf->{"noprint"} and $cf->{"noprint"}
!ll&&!rl&&r
0252
MC/DC50%1/2
exists $cf->{"noprint"} and $cf->{"noprint"}
exists $cf->{"noprint"} $cf->{"noprint"}
Truth table66%2/3
A and B
A= exists $cf->{"noprint"}B= $cf->{"noprint"}
ABresult
0X0
100
111
144 2 $myattribs->{display} = 0;
145 2 $display[$i] = 0;
146 # Need to remember the attributes set for this column
147 2 push(@columns, $myattribs);
148 2 next;
149 }
150  
151 25 ▶ if ( exists $cf->{format} and defined $cf->{format} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cf->{"format"} and defined $cf->{"format"}) 25 0 25
Condition33%1/3
exists $cf->{"format"} and defined $cf->{"format"}
!ll&&!rl&&r
0025
MC/DC0%0/2
exists $cf->{"format"} and defined $cf->{"format"}
exists $cf->{"format"} defined $cf->{"format"}
Truth table33%1/3
A and B
A= exists $cf->{"format"}B= defined $cf->{"format"}
ABresult
0X0
100
111
152 25 $format_names = $cf->{format};
153 1 ▶ no warnings 'redundant';
Subroutine BEGIN: called CC=1 SCAR=0.0
154 25 $width = length sprintf( $format_names, " " );
155 }
156  
157 25 ▶ if ( exists $cf->{justify} and defined $cf->{justify} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cf->{"justify"} and defined $cf->{"justify"}) 3 22 25
Condition66%2/3
exists $cf->{"justify"} and defined $cf->{"justify"}
!ll&&!rl&&r
0223
MC/DC50%1/2
exists $cf->{"justify"} and defined $cf->{"justify"}
exists $cf->{"justify"} defined $cf->{"justify"}
Truth table66%2/3
A and B
A= exists $cf->{"justify"}B= defined $cf->{"justify"}
ABresult
0X0
100
111
158 3 ▶ $justify = '^' if $cf->{justify} =~ m/^c/;
Branch: 1 branch
BranchTrueFalseTotal
if $cf->{"justify"} =~ /^c/ 1 2 3
159 3 ▶ $justify = '<' if $cf->{justify} =~ m/^l/;
Branch: 1 branch
BranchTrueFalseTotal
if $cf->{"justify"} =~ /^l/ 1 2 3
160 3 ▶ $justify = '>' if $cf->{justify} =~ m/^r/;
Branch: 1 branch
BranchTrueFalseTotal
if $cf->{"justify"} =~ /^r/ 1 2 3
161  
162 3 $myattribs->{justify} = $justify;
163 }
164  
165 25 ▶ if (exists $cf->{heading} and defined $cf->{heading}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cf->{"heading"} and defined $cf->{"heading"}) 9 16 25
Condition66%2/3
exists $cf->{"heading"} and defined $cf->{"heading"}
!ll&&!rl&&r
0169
MC/DC50%1/2
exists $cf->{"heading"} and defined $cf->{"heading"}
exists $cf->{"heading"} defined $cf->{"heading"}
Truth table66%2/3
A and B
A= exists $cf->{"heading"}B= defined $cf->{"heading"}
ABresult
0X0
100
111
166 9 $heading = $cf->{heading};
167 9 $myattribs->{heading} = $heading;
168 }
169
170 }
171  
172 26 push( @fmtfunc , $cf->{format_function} );
173 26 $myattribs->{fmtfunc} = $cf->{format_function};
174 26 ▶ push( @commify , $cf->{'commify'} || 0 );
Condition50%1/2
$cf->{'commify'} || 0
l!l
026
MC/DC0%0/1
$cf->{'commify'} || 0
$cf->{'commify'}
Truth table50%1/2
A
A= $cf->{'commify'}
Aresult
11
00
175 26 $myattribs->{commify} = $cf->{commify};
176  
177 26 $myattribs->{precision} = $cf->{precision};
178 26 $myattribs->{scale} = $cf->{scale};
179 26 $myattribs->{len} = $cf->{len};
180 }
181
182  
183 30 ▶ $heading = $names->[$i] unless $heading;
Branch: 1 branch
BranchTrueFalseTotal
unless $heading 21 9 30
184  
185 30 push(@heading, $heading);
186  
187 30 $type = $types->[$i];
188 30 $myattribs->{type} = $type;
189  
190 30 ▶ if ( $width ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($width) { } 25 5 30
191 25 push( @widths, $width );
192 25 $myattribs->{width} = $width;
193 } else {
194 push(@widths, $self->_determine_width(
195 5 $type, $sth->{PRECISION}->[$i] ));
196  
197 5 ▶ $widths[$i] = length $names->[$i]
Branch: 1 branch
BranchTrueFalseTotal
if length $names->[$i] > ($widths[$i] || 0) 1 4 5
Condition100%2/2
$widths[$i] || 0
l!l
41
MC/DC100%1/1
$widths[$i] || 0
$widths[$i]
Truth table100%2/2
A
A= $widths[$i]
Aresult
11
00
198 if (length $names->[$i] > ($widths[$i]||0));
199 5 $width = $widths[$i];
200 5 $myattribs->{width} = $width;
201 }
202  
203  
204 30 ▶ if ( $justify ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($justify) { } 30 0 30
205 30 push( @right_justify, $justify );
206 30 $myattribs->{justify} = $justify;
207 } else {
208 0 ▶ push(@right_justify,
Condition0%0/21
$type == &DBI::SQL_NUMERIC() || $type == &DBI::SQL_DECIMAL() || $type == &DBI::SQL_INTEGER() || $type == &DBI::SQL_SMALLINT() || $type == &DBI::SQL_FLOAT() || $type == &DBI::SQL_REAL() || $type == &DBI::SQL_BIGINT() || $type == &DBI::SQL_TINYINT()
l!l&&r!l&&!r
000
$type == &DBI::SQL_NUMERIC() or $type == &DBI::SQL_DECIMAL() or $type == &DBI::SQL_INTEGER() or $type == &DBI::SQL_SMALLINT() or $type == &DBI::SQL_FLOAT() or $type == &DBI::SQL_REAL() or $type == &DBI::SQL_BIGINT()
l!l&&r!l&&!r
000
$type == &DBI::SQL_NUMERIC() or $type == &DBI::SQL_DECIMAL() or $type == &DBI::SQL_INTEGER() or $type == &DBI::SQL_SMALLINT() or $type == &DBI::SQL_FLOAT() or $type == &DBI::SQL_REAL()
l!l&&r!l&&!r
000
$type == &DBI::SQL_NUMERIC() or $type == &DBI::SQL_DECIMAL() or $type == &DBI::SQL_INTEGER() or $type == &DBI::SQL_SMALLINT() or $type == &DBI::SQL_FLOAT()
l!l&&r!l&&!r
000
$type == &DBI::SQL_NUMERIC() or $type == &DBI::SQL_DECIMAL() or $type == &DBI::SQL_INTEGER() or $type == &DBI::SQL_SMALLINT()
l!l&&r!l&&!r
000
$type == &DBI::SQL_NUMERIC() or $type == &DBI::SQL_DECIMAL() or $type == &DBI::SQL_INTEGER()
l!l&&r!l&&!r
000
$type == &DBI::SQL_NUMERIC() or $type == &DBI::SQL_DECIMAL()
l!l&&r!l&&!r
000
MC/DC0%0/8
$type == &DBI::SQL_NUMERIC() || $type == &DBI::SQL_DECIMAL() || $type == &DBI::SQL_INTEGER() || $type == &DBI::SQL_SMALLINT() || $type == &DBI::SQL_FLOAT() || $type == &DBI::SQL_REAL() || $type == &DBI::SQL_BIGINT() || $type == &DBI::SQL_TINYINT()
$type == &DBI::SQL_NUMERIC() $type == &DBI::SQL_DECIMAL() $type == &DBI::SQL_INTEGER() $type == &DBI::SQL_SMALLINT() $type == &DBI::SQL_FLOAT() $type == &DBI::SQL_REAL() $type == &DBI::SQL_BIGINT() $type == &DBI::SQL_TINYINT()
Truth table0%0/9
A or B or C or D or E or F or G || H
A= $type == &DBI::SQL_NUMERIC()B= $type == &DBI::SQL_DECIMAL()C= $type == &DBI::SQL_INTEGER()D= $type == &DBI::SQL_SMALLINT()E= $type == &DBI::SQL_FLOAT()F= $type == &DBI::SQL_REAL()G= $type == &DBI::SQL_BIGINT()H= $type == &DBI::SQL_TINYINT()
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
001XXXXX1
0001XXXX1
00001XXX1
000001XX1
0000001X1
000000011
000000000
209 ($type == DBI::SQL_NUMERIC() ||
210 $type == DBI::SQL_DECIMAL() ||
211 $type == DBI::SQL_INTEGER() ||
212 $type == DBI::SQL_SMALLINT() ||
213 $type == DBI::SQL_FLOAT() ||
214 $type == DBI::SQL_REAL() ||
215 $type == DBI::SQL_BIGINT() ||
216 $type == DBI::SQL_TINYINT()));
217 $myattribs->{justify} =
218 0 ▶ ($type == DBI::SQL_NUMERIC() ||
Condition0%0/21
$type == &DBI::SQL_NUMERIC() || $type == &DBI::SQL_DECIMAL() || $type == &DBI::SQL_INTEGER() || $type == &DBI::SQL_SMALLINT() || $type == &DBI::SQL_FLOAT() || $type == &DBI::SQL_REAL() || $type == &DBI::SQL_BIGINT() || $type == &DBI::SQL_TINYINT()
l!l&&r!l&&!r
000
$type == &DBI::SQL_NUMERIC() or $type == &DBI::SQL_DECIMAL() or $type == &DBI::SQL_INTEGER() or $type == &DBI::SQL_SMALLINT() or $type == &DBI::SQL_FLOAT() or $type == &DBI::SQL_REAL() or $type == &DBI::SQL_BIGINT()
l!l&&r!l&&!r
000
$type == &DBI::SQL_NUMERIC() or $type == &DBI::SQL_DECIMAL() or $type == &DBI::SQL_INTEGER() or $type == &DBI::SQL_SMALLINT() or $type == &DBI::SQL_FLOAT() or $type == &DBI::SQL_REAL()
l!l&&r!l&&!r
000
$type == &DBI::SQL_NUMERIC() or $type == &DBI::SQL_DECIMAL() or $type == &DBI::SQL_INTEGER() or $type == &DBI::SQL_SMALLINT() or $type == &DBI::SQL_FLOAT()
l!l&&r!l&&!r
000
$type == &DBI::SQL_NUMERIC() or $type == &DBI::SQL_DECIMAL() or $type == &DBI::SQL_INTEGER() or $type == &DBI::SQL_SMALLINT()
l!l&&r!l&&!r
000
$type == &DBI::SQL_NUMERIC() or $type == &DBI::SQL_DECIMAL() or $type == &DBI::SQL_INTEGER()
l!l&&r!l&&!r
000
$type == &DBI::SQL_NUMERIC() or $type == &DBI::SQL_DECIMAL()
l!l&&r!l&&!r
000
MC/DC0%0/8
$type == &DBI::SQL_NUMERIC() || $type == &DBI::SQL_DECIMAL() || $type == &DBI::SQL_INTEGER() || $type == &DBI::SQL_SMALLINT() || $type == &DBI::SQL_FLOAT() || $type == &DBI::SQL_REAL() || $type == &DBI::SQL_BIGINT() || $type == &DBI::SQL_TINYINT()
$type == &DBI::SQL_NUMERIC() $type == &DBI::SQL_DECIMAL() $type == &DBI::SQL_INTEGER() $type == &DBI::SQL_SMALLINT() $type == &DBI::SQL_FLOAT() $type == &DBI::SQL_REAL() $type == &DBI::SQL_BIGINT() $type == &DBI::SQL_TINYINT()
Truth table0%0/9
A or B or C or D or E or F or G || H
A= $type == &DBI::SQL_NUMERIC()B= $type == &DBI::SQL_DECIMAL()C= $type == &DBI::SQL_INTEGER()D= $type == &DBI::SQL_SMALLINT()E= $type == &DBI::SQL_FLOAT()F= $type == &DBI::SQL_REAL()G= $type == &DBI::SQL_BIGINT()H= $type == &DBI::SQL_TINYINT()
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
001XXXXX1
0001XXXX1
00001XXX1
000001XX1
0000001X1
000000011
000000000
219 $type == DBI::SQL_DECIMAL() ||
220 $type == DBI::SQL_INTEGER() ||
221 $type == DBI::SQL_SMALLINT() ||
222 $type == DBI::SQL_FLOAT() ||
223 $type == DBI::SQL_REAL() ||
224 $type == DBI::SQL_BIGINT() ||
225 $type == DBI::SQL_TINYINT());
226 }
227  
228 30 ▶ $format_names = $justify x $width
Branch: 1 branch
BranchTrueFalseTotal
unless $format_names 5 25 30
229 unless $format_names;
230
231 push( @ul, defined $set->{underline}
232 30 ▶ ? "$set->{underline}" x $width
Branch: 1 branch
BranchTrueFalseTotal
defined $set->{'underline'} ? : 28 2 30
233 : '-' x $width
234 );
235
236  
237 $set->{linesize} += $widths[$i]
238 30 ▶ unless $set->{linesize};
Branch: 1 branch
BranchTrueFalseTotal
unless $set->{"linesize"} 0 30 30
239  
240 30 $format_row .= $format_names;
241 30 $format_row .= $set->{headsep};
242  
243  
244 30 push(@columns, $myattribs);
245 }
246  
247 20 $self->{'formats'} = \$format_row;
248 20 $self->{'columns'} = \@columns;
249 20 $self->{'headings'} = \@heading;
250 20 $self->{'ul'} = \@ul;
251  
252 20 $column_header_format = $format_row;
253 # print $fh form $header_form, (sprintf($format_row, @heading)), "\n" if $set->{heading};
254 print $fh form $column_header_format, @heading
255 20 ▶ if $set->{heading};
Branch: 1 branch
BranchTrueFalseTotal
if $set->{"heading"} 20 0 20
256 print $fh form $column_header_format, @ul
257 20 ▶ if $set->{underline};
Branch: 1 branch
BranchTrueFalseTotal
if $set->{"underline"} 18 2 20
258 print $fh "\n"
259 20 ▶ if $set->{heading} and ! $set->{underline};
Branch: 1 branch
BranchTrueFalseTotal
if $set->{"heading"} and not $set->{"underline"} 2 18 20
Condition66%2/3
$set->{"heading"} and not $set->{"underline"}
!ll&&!rl&&r
0182
MC/DC50%1/2
$set->{"heading"} and not $set->{"underline"}
$set->{"heading"} not $set->{"underline"}
Truth table66%2/3
A and not(B)
A= $set->{"heading"}B= not $set->{"underline"}
ABresult
0X0
100
111
260 }
261  
262 0 ▶sub re_headers {
Subroutine re_headers: not called CC=7 SCAR=40.3
Pod undocumented
263 0 my($self) = @_;
264 0 my $fh = $self->{'fh'};
265  
266  
267 0 my ($set, $column_format, $column_header_format, $sqlminus);
268  
269 0 ▶ if ( exists $self->{plugin}->{sqlminus} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'plugin'}{'sqlminus'}) { } 0 0 0
270 # sqlminus plugin installed.
271 0 $sqlminus = $self->{plugin}->{sqlminus};
272 0 $set = $sqlminus->{set_current};
273 } else {
274 0 return warn 'sqlminus plugin not installed\n';
275 }
276  
277 0 $column_header_format = ${$self->{'formats'}};
278  
279 print $fh "\n"
280 0 ▶ if defined $set->{heading};
Branch: 1 branch
BranchTrueFalseTotal
if defined $set->{"heading"} 0 0 0
281 0 print $fh form $column_header_format, @{$self->{headings}}
282 0 ▶ if defined $set->{heading};
Branch: 1 branch
BranchTrueFalseTotal
if defined $set->{"heading"} 0 0 0
283 0 print $fh form $column_header_format, @{$self->{ul}}
284 0 ▶ if defined $set->{underline};
Branch: 1 branch
BranchTrueFalseTotal
if defined $set->{"underline"} 0 0 0
285 print $fh "\n"
286 0 ▶ if defined $set->{heading} and not defined $set->{underline};
Branch: 1 branch
BranchTrueFalseTotal
if defined $set->{"heading"} and not defined $set->{"underline"} 0 0 0
Condition0%0/3
defined $set->{"heading"} and not defined $set->{"underline"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $set->{"heading"} and not defined $set->{"underline"}
defined $set->{"heading"} not defined $set->{"underline"}
Truth table0%0/3
A and not(B)
A= defined $set->{"heading"}B= not defined $set->{"underline"}
ABresult
0X0
100
111
287  
288 }
289  
290  
291 200 ▶sub row {
Subroutine row: called CC=21 SCAR=46.8
Pod undocumented
292 200 my($self, $orig_row) = @_;
293 200 my $i = 0;
294 200 my @row = $self->SUPER::row([@$orig_row]); # don't alter original
295  
296 200 my $columns = $self->{'columns'};
297  
298 200 my $breaks = $self->{'breaks'};
299  
300 200 my $format_rows = ${$self->{'formats'}};
301  
302 # if (exists $self->{'formats'} and defined $self->{'formats'} ){
303 # #print "using existing format '$format_rows'\n";
304 # $format_rows = ${$self->{'formats'}};
305 # } else {
306 # for (my $i = 0; $i < $sth->{'NUM_OF_FIELDS'}; $i++) {
307 # $format_rows .=
308 # ($right_justify->[$i] ? "<" : ">")
309 # x $widths->[$i]
310 # . ($self->{recsep}?$self->{recsepchar}:'');
311 # }
312 # }
313  
314 200 $format_rows .= "\n";
315  
316 200 my $fh = $self->{'fh'};
317 200 my @data; my $skip_rows = 0; my $skip_page = undef;
318 COLUMN:
319 200 ▶ for (my $i = 0; $i < $self->{'sth'}->{'NUM_OF_FIELDS'}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"sth"}{"NUM_OF_FIELDS"}) 320 200 520
320  
321 320 my $attribs = $columns->[$i];
322 320 ▶ if ( exists $breaks->{$attribs->{name_lc}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$breaks{$attribs->{"name_lc"}}) 0 320 320
323  
324 0 my $brk = $breaks->{$attribs->{name_lc}};
325  
326 0 ▶ if (defined $brk->{last_break_point} and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $brk->{"last_break_point"} and $brk->{"last_break_point"} ne $row[$i]) 0 0 0
Condition0%0/3
defined $brk->{"last_break_point"} and $brk->{"last_break_point"} ne $row[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $brk->{"last_break_point"} and $brk->{"last_break_point"} ne $row[$i]
defined $brk->{"last_break_point"} $brk->{"last_break_point"} ne $row[$i]
Truth table0%0/3
A and B
A= defined $brk->{"last_break_point"}B= $brk->{"last_break_point"} ne $row[$i]
ABresult
0X0
100
111
327 $brk->{last_break_point} ne $row[$i]) {
328 0 ▶ if (exists $brk->{skip}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $brk->{"skip"}) 0 0 0
329 $skip_rows = $skip_rows >= $brk->{skip} ? $skip_rows :
330 0 ▶ $brk->{skip};
Branch: 1 branch
BranchTrueFalseTotal
$skip_rows >= $brk->{'skip'} ? : 0 0 0
331 }
332  
333 0 ▶ if (exists $brk->{skip_page}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $brk->{"skip_page"}) 0 0 0
334 0 $skip_page = 1;
335 }
336 }
337  
338 0 ▶ if (exists $brk->{nodup}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $brk->{"nodup"}) 0 0 0
339 0 ▶ if (defined $brk->{last_break_point}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $brk->{"last_break_point"} and $brk->{"last_break_point"} eq $row[$i]) 0 0 0
Condition0%0/3
defined $brk->{"last_break_point"} and $brk->{"last_break_point"} eq $row[$i]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $brk->{"last_break_point"} and $brk->{"last_break_point"} eq $row[$i]
defined $brk->{"last_break_point"} $brk->{"last_break_point"} eq $row[$i]
Truth table0%0/3
A and B
A= defined $brk->{"last_break_point"}B= $brk->{"last_break_point"} eq $row[$i]
ABresult
0X0
100
111
340 and $brk->{last_break_point} eq $row[$i]) {
341 0 push (@data, q{}); # empty row (noduplicate display)
342 0 $brk->{last_break_point} = $row[$i];
343 0 next COLUMN;
344 }
345 }
346  
347 0 $brk->{last_break_point} = $row[$i];
348 }
349  
350 320 ▶ next unless ($attribs->{'display'});
Branch: 1 branch
BranchTrueFalseTotal
unless $attribs->{"display"} 20 300 320
351  
352 300 ▶ if ((ref $attribs->{fmtfunc}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attribs->{'fmtfunc'} eq 'CODE') { } 0 300 300
353 # warn "fmtcall\n";
354 push( @data ,
355 $attribs->{fmtfunc}(
356 $row[$i]
357 ,$attribs->{precision} || $attribs->{width}
358 ,$attribs->{scale} || 0
359 0 ▶ ,$attribs->{'commify'}) );
Condition0%0/5
$attribs->{'precision'} || $attribs->{'width'}
l!l&&r!l&&!r
000
$attribs->{'scale'} || 0
l!l
00
MC/DC0%0/2
$attribs->{'precision'} || $attribs->{'width'}
$attribs->{'precision'} $attribs->{'width'}
MC/DC0%0/1
$attribs->{'scale'} || 0
$attribs->{'scale'}
Truth table0%0/3
A || B
A= $attribs->{'precision'}B= $attribs->{'width'}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $attribs->{'scale'}
Aresult
11
00
360 } else {
361 300 push( @data , $row[$i] );
362 }
363 }
364  
365 # Deal with the breaks.
366 200 ▶ if ($skip_page) {
Branch: 2 branches
BranchTrueFalseTotal
if ($skip_page) { } 0 200 200
elsif ($skip_rows) { } 0 200 200
367 0 print $fh q{ };
368 } elsif ($skip_rows) {
369 0 print $fh "\n" x $skip_rows;
370 }
371  
372 200 print $fh form (
373 { 'break' => break_with('') }
374 , $format_rows, @data
375 );
376  
377 200 ++$self->{'rows'};
378  
379 # Send a undef back to caller, signal limit reached.
380 200 ▶ if (defined $self->{limit} and $self->{rows} >= $self->{limit}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"limit"} and $self->{"rows"} >= $self->{"limit"}) 0 200 200
Condition33%1/3
defined $self->{"limit"} and $self->{"rows"} >= $self->{"limit"}
!ll&&!rl&&r
20000
MC/DC0%0/2
defined $self->{"limit"} and $self->{"rows"} >= $self->{"limit"}
defined $self->{"limit"} $self->{"rows"} >= $self->{"limit"}
Truth table33%1/3
A and B
A= defined $self->{"limit"}B= $self->{"rows"} >= $self->{"limit"}
ABresult
0X0
100
111
381 0 return undef;
382 }
383 # Determine if this number of rows displayed is modulo of pagesize
384 200 ▶ if (defined $self->{pagesize}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"pagesize"} and $self->{"rows"} % $self->{"pagesize"} == 0) 0 200 200
Condition33%1/3
defined $self->{"pagesize"} and $self->{"rows"} % $self->{"pagesize"} == 0
!ll&&!rl&&r
20000
MC/DC0%0/2
defined $self->{"pagesize"} and $self->{"rows"} % $self->{"pagesize"} == 0
defined $self->{"pagesize"} $self->{"rows"} % $self->{"pagesize"} == 0
Truth table33%1/3
A and B
A= defined $self->{"pagesize"}B= $self->{"rows"} % $self->{"pagesize"} == 0
ABresult
0X0
100
111
385 and ($self->{'rows'} % $self->{pagesize}) == 0 ) {
386 0 $self->re_headers();
387 }
388  
389 200 return $self->{rows};
390 }
391  
392  
393 20 ▶sub trailer {
Subroutine trailer: called CC=1 SCAR=0.0
Pod undocumented
394 20 my $self = shift;
395 20 my $widths = delete $self->{'widths'};
396 20 my $right_justify = delete $self->{'right_justify'};
397  
398 20 delete $self->{recsep};
399 20 delete $self->{recsepchar};
400 20 print "Page Number: ", $self->{pagenum}, "\n";
401  
402 20 $self->SUPER::trailer(@_);
403 }
404  
405 1 1;
406  
407 =head1 NAME
408  
409 DBI::Format::SQLMinus - A package for displaying result tables
410  
411 =head1 SYNOPSIS
412  
413 =head1 DESCRIPTION
414  
415 THIS PACKAGE IS STILL VERY EXPERIMENTAL. THINGS WILL CHANGE.
416  
417 =head1 AUTHOR AND COPYRIGHT
418  
419 Orignal Format module is Copyright (c) 1997, 1998
420  
421 Jochen Wiedmann
422 Am Eisteich 9
423 72555 Metzingen
424 Germany
425  
426 Email: joe@ispsoft.de
427 Phone: +49 7123 14887
428  
429 SQLMinus is Copyright (c) 2001, 2002 Thomas A. Lowery
430  
431 The DBI::Format::SQLMinus module is free software; you can redistribute it and/or
432 modify it under the same terms as Perl itself.
433  
434  
435 =head1 SEE ALSO
436  
437 L<DBI::Shell>, L<DBI>, L<dbish>
« blib/lib/DBI/Shell/Completion.pm ↑ Summary blib/lib/DBI/Shell/Spool.pm »