blib/lib/DBI/Shell/SQLMinus.pm

filter: Statementstmt 44.6% 181 / 405 Branchbran 31.8% 91 / 286 Conditioncond 31.2% 10 / 32 MC/DCmcdc 6.2% 1 / 16 Subroutinesub 42.8% 15 / 35 Podpod 0.0% 0 / 13 totaltotal 37.8% 298 / 787 CC 171 SCAR 55.2
CC
171
Cov
39%
do_break
812.0
_determine_format
285.5
do_column
280.8
CRAP 249.3
↑ Summary blib/lib/DBI/Shell.pm »
1 #!perl -w
2 # vim:ts=4:sw=4:aw:ai:nowrapscan
3 #
4 #
5  
6 package DBI::Shell::SQLMinus;
7  
8 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Text::Abbrev ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Text::ParseWords;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Text::Wrap;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use IO::Tee;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub init {
17 4 ▶ my ($class, $sh, @args) = @_;
Subroutine init: called CC=3 SCAR=11.1
Pod undocumented
18 4 ▶ $class = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
19 4 my $sqlminus = {
20 archive => {
21 log => undef,
22 },
23 'breaks' => {
24 skip => [ qw{text} ],
25 skip_page => [ qw{text} ],
26 dup => [ qw{text} ],
27 nodup => [ qw{text} ],
28 },
29 break_current => {
30 },
31 'clear' => {
32 break => undef,
33 buffer => undef,
34 columns => undef,
35 computes => undef,
36 screen => undef,
37 sql => undef,
38 timing => undef,
39 },
40 db => undef,
41 dbh => undef,
42 column => {
43 column_name => [ qw{text} ],
44 alias => [ qw{text} ],
45 clear => [ qw{command} ],
46 fold_after => [ qw{text} ],
47 fold_before => [ qw{text} ],
48 format => [ qw{text} ],
49 heading => [ qw{text} ],
50 justify => [ qw{c l r f} ],
51 like => [ qw{text} ],
52 'length' => [ qw{text} ],
53 newline => [ qw{text} ],
54 new_value => [ qw{text} ],
55 noprint => [ qw{on off} ],
56 'print' => [ qw{on off} ],
57 null => [ qw{text} ],
58 on => 1,
59 off => 0,
60 truncated => [ qw{on off} ],
61 type => [ qw{text} ],
62 wordwrapped => [ qw{on off} ],
63 wrapped => [ qw{on off} ],
64 column_format => undef,
65 format_function => undef,
66 precision => undef,
67 scale => undef,
68 },
69 # hash ref contains formats for code.
70 column_format => {
71 },
72 # Hash ref contains the formats for the column headers.
73 column_header_format => {
74 },
75 commands => {
76 '@' => undef,
77 'accept'=> undef,
78 append => undef,
79 attribute => undef,
80 break => undef,
81 btitle => undef,
82 change => undef,
83 clear => undef,
84 copy => undef,
85 column => undef,
86 compute => undef,
87 define => undef,
88 edit => undef,
89 'exec' => undef,
90 get => undef,
91 pause => undef,
92 prompt => undef,
93 repheader=> undef,
94 repfooter=> undef,
95 run => undef,
96 save => undef,
97 set => undef,
98 show => undef,
99 start => undef,
100 ttitle => undef,
101 undefine=> undef,
102 },
103 set_current => {
104 appinfo => undef,
105 arraysize => undef,
106 autocommit => undef,
107 autoprint => undef,
108 autorecovery=> undef,
109 autotrace => undef,
110 blockterminator=> undef,
111 buffer => undef,
112 closecursor => undef,
113 cmdsep => undef,
114 compatibility=> undef,
115 concat => undef,
116 copycommit => undef,
117 copytypecheck=> undef,
118 define => undef,
119 document => undef,
120 echo => undef,
121 editfile => undef,
122 embedded => undef,
123 escape => undef,
124 feedback => undef,
125 flagger => undef,
126 flush => undef,
127 heading => 1,
128 headsep => ' ',
129 instance => undef,
130 linesize => 72,
131 limit => undef,
132 loboffset => undef,
133 logsource => undef,
134 long => undef,
135 longchunksize => undef,
136 maxdata => undef,
137 newpage => undef,
138 null => undef,
139 numwidth => undef,
140 pagesize => undef,
141 pause => undef,
142 recsep => 1,
143 recsepchar => ' ',
144 scan => qq{obsolete command: use 'set define' instead},
145 serveroutput=> undef,
146 shiftinout => undef,
147 showmode => undef,
148 space => qq{obsolete command: use 'set define' instead},
149 sqlblanklines=> undef,
150 sqlcase => undef,
151 sqlcontinue => undef,
152 sqlnumber => undef,
153 sqlprefix => undef,
154 sqlprompt => undef,
155 sqlterminator=> undef,
156 suffix => undef,
157 tab => undef,
158 termout => undef,
159 'time' => undef,
160 'timing' => undef,
161 trimout => undef,
162 trimspool => undef,
163 'truncate' => undef,
164 underline => '-',
165 verify => undef,
166 wrap => undef,
167 },
168 # Each set command may call a custom function. Included are
169 # currently defined sets. For simple set/get, the value is
170 # stored set_current.
171 set_commands => {
172  
173 appinfo => ['_unimp'],
174 arraysize => ['_unimp'],
175 autocommit => ['_unimp'],
176 autoprint => ['_unimp'],
177 autorecovery => ['_unimp'],
178 autotrace => ['_unimp'],
179  
180 blockterminator => ['_unimp'],
181 buffer => ['_unimp'],
182  
183 closecursor => ['_unimp'],
184 cmdsep => ['_unimp'],
185 compatibility => ['_unimp'],
186 concat => ['_unimp'],
187 copycommit => ['_unimp'],
188 copytypecheck => ['_unimp'],
189  
190 define => ['_unimp'],
191 document => ['_unimp'],
192  
193 echo => ['_set_get'],
194 editfile => ['_unimp'],
195 embedded => ['_unimp'],
196 escape => ['_unimp'],
197  
198 feedback => ['_unimp'],
199 flagger => ['_unimp'],
200 flush => ['_unimp'],
201  
202 heading => ['_set_get'],
203 headsep => ['_set_get'],
204  
205 instance => ['_unimp'],
206  
207 linesize => ['_set_get'],
208 limit => ['_set_get'],
209 loboffset => ['_unimp'],
210 logsource => ['_unimp'],
211 long => ['_unimp'],
212 longchunksize => ['_unimp'],
213  
214 maxdata => ['_unimp'],
215  
216 newpage => ['_unimp'],
217 null => ['_set_get'],
218 numwidth => ['_unimp'],
219  
220 pagesize => ['_set_get'],
221 pause => ['_unimp'],
222  
223 recsep => ['_set_get'],
224 recsepchar => ['_set_get'],
225  
226 scan => ['_print_buffer',
227 qq{obsolete command: use 'set define' instead}],
228 serveroutput => ['_unimp'],
229 shiftinout => ['_unimp'],
230 showmode => ['_unimp'],
231 space => ['_print_buffer',
232 qq{obsolete command: use 'set define' instead}],
233 sqlblanklines => ['_unimp'],
234 sqlcase => ['_unimp'],
235 sqlcontinue => ['_unimp'],
236 sqlnumber => ['_unimp'],
237 sqlprefix => ['_unimp'],
238 sqlprompt => ['_unimp'],
239 sqlterminator => ['_unimp'],
240 suffix => ['_unimp'],
241  
242 tab => ['_unimp'],
243 termout => ['_unimp'],
244 'time' => ['_unimp'],
245 'timing' => ['_unimp'],
246 trimout => ['_unimp'],
247 trimspool => ['_unimp'],
248 'truncate' => ['_unimp'],
249  
250 underline => ['_set_get'],
251  
252 verify => ['_unimp'],
253  
254 wrap => ['_unimp'],
255 },
256 show => {
257 all => ['_all'],
258  
259 btitle => ['_unimp'],
260  
261 catalogs => ['_unimp'],
262 columns => ['_unimp'],
263  
264 errors => ['_unimp'],
265  
266 grants => ['_unimp'],
267  
268 help => ['_help'],
269 hints => ['_hints'],
270  
271 lno => ['_hints'],
272  
273 me => ['_me'],
274  
275 objects => ['_unimp'],
276  
277 packages => ['_unimp'],
278 parameters => ['_unimp'],
279 password => ['_print_buffer', qq{I don\'t think so!}],
280 pno => ['_unimp'],
281  
282 release => ['_unimp'],
283 repfooter => ['_unimp'],
284 repheader => ['_unimp'],
285 roles => ['_unimp'],
286  
287 schemas => ['_schemas'],
288 sga => ['_unimp'],
289 show => ['_show_all_commands'],
290 spool => ['_spool'],
291 sqlcode => ['_sqlcode'],
292  
293 ttitle => ['_unimp'],
294 tables => ['_tables'],
295 types => ['_types'],
296  
297 users => ['_unimp'],
298  
299 views => ['_views'],
300 },
301 sql => {
302 pno => undef,
303 lno => undef,
304 release => undef,
305 user => undef,
306 },
307 };
308  
309 4 my $pi = bless $sqlminus, $class;
310  
311 # add the sqlminus object to the plugin list for reference later.
312 4 $sh->{plugin}->{sqlminus} = $pi;
313  
314 4 $pi->{dbh} = \$sh->{dbh};
315  
316 4 my $com_ref = $sh->{commands};
317  
318 4 foreach (sort keys %{$pi->{commands}}) {
319 104 $com_ref->{$_} = {
320 hint => "SQLMinus: $_",
321 };
322 }
323 4 return $pi;
324 }
325 # 'btittle' => {
326 # off => undef,
327 # on => undef,
328 # col => undef,
329 # skip => undef,
330 # tab => undef,
331 # left => undef,
332 # center => undef,
333 # right => undef,
334 # bold => undef,
335 # format => undef,
336 # text => undef,
337 # variable => undef,
338 # },
339 #
340 # break.
341 #
342 # BRE[AK] [ON report_element [action [action]]] ...
343 #
344 # where:
345 #
346 # report_element
347 #
348 # Requires the following syntax:
349 #
350 # {column|expr|ROW|REPORT}
351 #
352 # action
353 #
354 # Requires the following syntax:
355 #
356 # [SKI[P] n|[SKI[P]] PAGE][NODUP[LICATES]|DUP[LICATES]]
357 #
358 sub do_break {
359 0 ▶ my ($self, $command, @args) = @_;
Subroutine do_break: not called CC=28 SCAR=67.0
Pod undocumented
360  
361 # print "break command:\n";
362  
363 0 my $breaks = $self->{plugin}->{sqlminus}->{breaks};
364 0 my $cbreaks = $self->{plugin}->{sqlminus}->{break_current};
365  
366 0 ▶ unless( $command ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($command) 0 0 0
367 0 my $maxlen = 0;
368 0 foreach (keys %$cbreaks ) {
369 0 ▶ $maxlen = (length $_ > $maxlen? length $_ : $maxlen );
Branch: 1 branch
BranchTrueFalseTotal
length $_ > $maxlen ? : 0 0 0
370 }
371 0 my $format = sprintf("%%-%ds", $maxlen );
372 0 foreach my $col_name (sort keys %$cbreaks) {
373 0 $self->log( sprintf( $format, $col_name ));
374 0 foreach my $col (sort keys %$breaks) {
375 0 ▶ next unless $cbreaks->{$col_name}->{$col};
Branch: 1 branch
BranchTrueFalseTotal
unless $cbreaks->{$col_name}{$col} 0 0 0
376 $self->print_buffer_nop(sprintf( "\t%-15s %s\n", $col,
377 0 ▶ ($cbreaks->{$col_name}->{$col}||'undef') ));
Condition0%0/2
$cbreaks->{$col_name}{$col} || 'undef'
l!l
00
MC/DC0%0/1
$cbreaks->{$col_name}{$col} || 'undef'
$cbreaks->{$col_name}{$col}
Truth table0%0/2
A
A= $cbreaks->{$col_name}{$col}
Aresult
11
00
378 }
379 }
380 0 return;
381 }
382  
383 0 my @words = quotewords('\s+', 0, join( " ", @args));
384  
385 WORD:
386 0 ▶ while(@words) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words) 0 0 0
387 0 my $val = shift @words;
388  
389 0 ▶ if ($val =~ m/row/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($val =~ /row/i) { } 0 0 0
elsif ($val =~ /report/i) { } 0 0 0
elsif ($val =~ /on/i) { } 0 0 0
390 } elsif ($val =~ m/report/i ) {
391 } elsif ($val =~ m/on/i ) { # Skip on
392 0 next WORD;
393 } else {
394 # Handle a column.
395 0 ▶ if (exists $cbreaks->{$val}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cbreaks->{$val}) 0 0 0
396 0 delete $cbreaks->{$val};
397 }
398 0 $cbreaks->{$val} = {
399 skip => undef
400 , nodup => undef
401 }; # Create the column in the break group.
402  
403 ACTION:
404 0 ▶ while(@words) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words) 0 0 0
405 0 my $action = shift @words;
406 0 $self->print_buffer_nop( "actin $action" );
407 0 ▶ last unless $action =~ m/\bskip|\bpage|\bnodup|\bdup/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $action =~ /\bskip|\bpage|\bnodup|\bdup/i 0 0 0
408
409 # These are the accepted action given to a break.
410 0 ▶ if ($action =~ m/\bskip/i ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($action =~ /\bskip/i) { } 0 0 0
elsif ($action =~ /\bnodup/i) { } 0 0 0
elsif ($action =~ /\bdup/i) { } 0 0 0
elsif ($action =~ /\bpage/i) { } 0 0 0
411 # Skip consumes the next value, either page or a number.
412 0 ▶ my $skip_val = shift @words if (@words);
Branch: 1 branch
BranchTrueFalseTotal
if @words 0 0 0
413 0 ▶ unless ($skip_val) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($skip_val) 0 0 0
414 0 $self->print_buffer(
415 qq{break: action $action number lines|page} );
416 0 last;
417 }
418  
419 0 $self->print_buffer_nop( "action $action $skip_val" );
420 0 ▶ if ($skip_val =~ m/(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip_val =~ /(\d+)/) { } 0 0 0
421 0 $cbreaks->{$val}->{skip} = $skip_val;
422 delete $cbreaks->{$val}->{skip_page}
423 0 ▶ if (exists $cbreaks->{$val}->{skip_page});
Branch: 1 branch
BranchTrueFalseTotal
if exists $cbreaks->{$val}{"skip_page"} 0 0 0
424 } else {
425 0 $cbreaks->{$val}->{skip_page} = 1;
426 delete $cbreaks->{$val}->{skip}
427 0 ▶ if (exists $cbreaks->{$val}->{skip});
Branch: 1 branch
BranchTrueFalseTotal
if exists $cbreaks->{$val}{"skip"} 0 0 0
428 }
429 # Default value, if nodup/dup is not defined, add.
430 0 unshift @words, 'nodup';
431 unshift @words, 'nodup' unless (exists
432 $cbreaks->{$val}->{dup} or exists
433 0 ▶ $cbreaks->{$val}->{nodup});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $cbreaks->{$val}{"dup"} or exists $cbreaks->{$val}{"nodup"} 0 0 0
Condition0%0/3
exists $cbreaks->{$val}{"dup"} or exists $cbreaks->{$val}{"nodup"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $cbreaks->{$val}{"dup"} or exists $cbreaks->{$val}{"nodup"}
exists $cbreaks->{$val}{"dup"} exists $cbreaks->{$val}{"nodup"}
Truth table0%0/3
A or B
A= exists $cbreaks->{$val}{"dup"}B= exists $cbreaks->{$val}{"nodup"}
ABresult
1X1
011
000
434  
435 } elsif ($action =~ m/\bnodup/i ) {
436 0 $cbreaks->{$val}->{nodup} = 1;
437 delete $cbreaks->{$val}->{dup}
438 0 ▶ if (exists $cbreaks->{$val}->{dup});
Branch: 1 branch
BranchTrueFalseTotal
if exists $cbreaks->{$val}{"dup"} 0 0 0
439 } elsif ($action =~ m/\bdup/i ) {
440 0 $cbreaks->{$val}->{dup} = 1;
441 delete $cbreaks->{$val}->{nodup}
442 0 ▶ if (exists $cbreaks->{$val}->{nodup});
Branch: 1 branch
BranchTrueFalseTotal
if exists $cbreaks->{$val}{"nodup"} 0 0 0
443 } elsif ($action =~ m/\bpage/i ) {
444 # Put skip in front of the value and let the skip command handle it.
445 0 unshift @words, 'skip', $action;
446 } else {
447 0 $self->print_buffer(
448 qq{break: action $action unknown, ambiguous, or not supported.} );
449 0 last;
450 }
451 }
452 }
453 0 return;
454 }
455  
456 return
457 0 $self->print_buffer(
458 qq{break: $command unknown, ambiguous, or not supported.} );
459 }
460  
461 #
462 # set
463 #
464 sub do_set {
465 24 ▶ my ($self, $command, @args) = @_;
Subroutine do_set: called CC=13 SCAR=40.4
Pod undocumented
466  
467  
468 # print "set command:\n";
469  
470 24 my $set = $self->{plugin}->{sqlminus}->{set_current};
471  
472 24 ▶ unless( $command ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($command) 0 24 24
473 0 my $maxlen = 0;
474 0 foreach (keys %$set ) {
475 0 ▶ $maxlen = (length $_ > $maxlen? length $_ : $maxlen );
Branch: 1 branch
BranchTrueFalseTotal
length $_ > $maxlen ? : 0 0 0
476 }
477 0 my $format = sprintf("%%-%ds %%s", $maxlen );
478 0 foreach (sort keys %$set) {
479 $self->log(
480 0 ▶ sprintf( $format, $_, $set->{$_} || 'undef' )
Condition0%0/2
$set->{$_} || 'undef'
l!l
00
MC/DC0%0/1
$set->{$_} || 'undef'
$set->{$_}
Truth table0%0/2
A
A= $set->{$_}
Aresult
11
00
481 );
482 }
483 0 return;
484 }
485  
486 24 my $options = Text::Abbrev::abbrev(keys %$set);
487  
488 24 my $ref = $self->{plugin}->{sqlminus};
489  
490 24 ▶ if (my $c = $options->{$command}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $options->{$command}) 24 0 24
491 24 $self->log( "command: $command " . ref $c . "" );
492 24 ▶ if (my $c = $options->{$command}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $options->{$command}) 24 0 24
493 24 my ($cmd, @cargs) = @{$ref->{set_commands}->{$c}};
494 24 ▶ push(@args, @cargs) if @cargs;
Branch: 1 branch
BranchTrueFalseTotal
if @cargs 0 24 24
495 24 return $self->{plugin}->{sqlminus}->$cmd(\$self,$c,@args);
496 }
497 }
498 0 my %l;
499 0 ▶ foreach (keys %$options) { $l{$options->{$_}}++ if m/^$command/ }
Branch: 1 branch
BranchTrueFalseTotal
if /^$command/ 0 0 0
500 0 my $sug = wrap( "\t(", "\t\t", sort keys %l );
501 0 ▶ $sug = "\n$sug)" if defined $sug;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sug 0 0 0
502 0 ▶ $sug = q{} unless defined $sug;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sug 0 0 0
503 return
504 0 $self->print_buffer(
505 qq{set: $command unknown, ambiguous, or not supported.$sug} );
506 }
507  
508 # show
509 sub do_show {
510 1 ▶ my ($self, $command, @args) = @_;
Subroutine do_show: called CC=8 SCAR=29.3
Pod undocumented
511  
512 1 ▶ return unless $command;
Branch: 1 branch
BranchTrueFalseTotal
unless $command 0 1 1
513  
514 1 my $show = $self->{plugin}->{sqlminus}->{show};
515 1 my $ref = $self->{plugin}->{sqlminus};
516  
517 1 my $options = Text::Abbrev::abbrev(keys %$show);
518 1 ▶ if (my $c = $options->{$command}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $options->{$command}) 1 0 1
519 1 my ($cmd, @cargs) = @{$ref->{show}->{$c}};
520 1 ▶ push(@args, @cargs) if @cargs;
Branch: 1 branch
BranchTrueFalseTotal
if @cargs 0 1 1
521 1 return $self->{plugin}->{sqlminus}->$cmd(\$self,@args);
522 }
523 0 my %l;
524 0 ▶ foreach (keys %$options) { $l{$options->{$_}}++ if m/^$command/ }
Branch: 1 branch
BranchTrueFalseTotal
if /^$command/ 0 0 0
525 0 my $sug = wrap( "\t(", "\t\t", sort keys %l );
526 0 ▶ $sug = "\n$sug)" if defined $sug;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sug 0 0 0
527 0 ▶ $sug = q{} unless defined $sug; # rid warnings
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sug 0 0 0
528 return
529 0 $self->print_buffer(
530 qq{show: $command unknown, ambiguous, or not supported.$sug} );
531 }
532  
533 #
534 # Attempt to allow the user to define format string for query results.
535 #
536  
537  
538 sub do_column {
539 53 ▶ my ($self, $command, @args) = @_;
Subroutine do_column: called CC=75 SCAR=56.4
Pod undocumented
540  
541 # print "column command:\n" if $self->{debug};
542  
543 # my $set = $column_format;
544 53 my $ref = $self->{plugin}->{sqlminus};
545 53 my $column = $ref->{column};
546 53 my $column_format = $ref->{column_format};
547 53 my $column_header_format = $ref->{column_header_format};
548  
549 # If just the format command is issued, print all the current formatted
550 # columns. Currently, only the column name is printed.
551 53 ▶ unless( $command ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($command) 11 42 53
552 11 my $maxlen = 0;
553 11 foreach (keys %$column_format ) {
554 15 ▶ $maxlen = (length $_ > $maxlen? length $_ : $maxlen );
Branch: 1 branch
BranchTrueFalseTotal
length $_ > $maxlen ? : 11 4 15
555 }
556 11 my $format = sprintf("%%-%ds", $maxlen );
557 11 foreach my $col_name (sort keys %$column_format) {
558 15 $self->log( sprintf( $format, $col_name ));
559 15 foreach my $col (sort keys %$column) {
560 375 ▶ next unless $column_format->{$col_name}->{$col};
Branch: 1 branch
BranchTrueFalseTotal
unless $column_format->{$col_name}{$col} 288 87 375
561 $self->print_buffer_nop(sprintf( "\t%-15s %s\n", $col,
562 87 ▶ ($column_format->{$col_name}->{$col}||'undef') ));
Condition50%1/2
$column_format->{$col_name}{$col} || 'undef'
l!l
870
MC/DC0%0/1
$column_format->{$col_name}{$col} || 'undef'
$column_format->{$col_name}{$col}
Truth table50%1/2
A
A= $column_format->{$col_name}{$col}
Aresult
11
00
563 }
564 }
565 11 return;
566 }
567  
568 42 ▶ if ( $command =~ m/clear/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command =~ /clear/i) 6 36 42
569 # clear the format for either one or all columns.
570 6 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 0 6 6
571 # Next argument column to clear.
572 0 my $f = shift @args;
573 # Format defined?
574 0 $self->_clear_format( \$column_format, $f );
575 } else {
576 # remove all column formats.
577  
578 6 foreach my $column (keys %$column_format) {
579 # warn "Removing format for : $column :\n";
580 8 $self->_clear_format( \$column_format, $column );
581 }
582  
583 # map { delete $column_format->{$_} } keys %$column_format
584 # if exists $ref->{column_format};
585 # map { delete $column_header_format->{$_} }
586 # keys %$column_header_format
587 # if exists $ref->{column_header_format};
588 }
589  
590 6 return $self->log( "format cleared" );
591 }
592  
593 #
594 # If column called with only a column name, display the current format.
595 #
596  
597 36 ▶ unless( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 3 33 36
598 return $self->log( "$command: no column format defined." )
599 3 ▶ unless exists $column_format->{$command};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $column_format->{$command} 2 1 3
600  
601 1 $self->log( "column $command format: " );
602 1 foreach my $col (sort keys %{$column_format->{$command}}) {
603 25 ▶ next unless $column_format->{$command}->{$col};
Branch: 1 branch
BranchTrueFalseTotal
unless $column_format->{$command}{$col} 19 6 25
604 $self->print_buffer_nop(sprintf( "\t%-15s %s"
605 , $col
606 6 ▶ , ($column_format->{$command}->{$col}||'undef') ));
Condition50%1/2
$column_format->{$command}{$col} || 'undef'
l!l
60
MC/DC0%0/1
$column_format->{$command}{$col} || 'undef'
$column_format->{$command}{$col}
Truth table50%1/2
A
A= $column_format->{$command}{$col}
Aresult
11
00
607 }
608 1 return;
609 }
610  
611 # print "column: $command ", join( " ", @args) , "\n" if $self->{debug};
612  
613 #
614 # column: column name.
615 #
616  
617 # Builds a structure of attributes supported in column formats.
618 33 my ($col, $col_head);
619 33 ▶ unless ( exists $column_format->{$command} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $column_format->{$command}) 8 25 33
620 8 my $struct = {};
621 8 foreach (keys %$column) {
622 200 $struct->{$_} = undef;
623 }
624 8 $column_format->{$command} = $struct;
625  
626 8 $col = $column_format->{$command};
627  
628 8 $col->{on} = 1;
629 8 $col->{off} = 0;
630 }
631  
632 33 ▶ $col = $column_format->{$command} unless $col;
Branch: 1 branch
BranchTrueFalseTotal
unless $col 25 8 33
633 33 ▶ $col_head = $column_header_format->{$command} unless $col_head;
Branch: 1 branch
BranchTrueFalseTotal
unless $col_head 33 0 33
634  
635  
636 33 my $options = Text::Abbrev::abbrev(keys %$column);
637  
638 # Handle quoted words or phrases.
639 33 my @words = quotewords('\s+', 0, join( " ", @args));
640  
641 print "column: $command ", join( " ", @words) , "\n"
642 33 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 33 33
643  
644 33 ▶ while(@words) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words) 71 29 100
645 71 my ( $text, $on, $off, $justify );
646 71 my $argv = shift @words;
647 71 ▶ my $c = exists $options->{$argv} ? $options->{$argv} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $options->{$argv} ? : 71 0 71
648 # determine if the current argument is part of the format
649 # string or a value.
650 71 ▶ if ($c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c) 71 0 71
651 71 ▶ if ( $c =~ m/alias/i ) {
Branch: 18 branches
BranchTrueFalseTotal
if ($c =~ /alias/i) { } 0 71 71
elsif ($c =~ /clear/i) { } 0 71 71
elsif ($c =~ /fold_after/i) { } 0 71 71
elsif ($c =~ /fold_before/i) { } 0 71 71
elsif ($c =~ /format/i) { } 27 44 71
elsif ($c =~ /heading/i) { } 22 22 44
elsif ($c =~ /justify/i) { } 17 5 22
elsif ($c =~ /like/i) { } 0 5 5
elsif ($c =~ /newline/i) { } 0 5 5
elsif ($c =~ /new_value/i) { } 0 5 5
elsif ($c =~ /noprint/i) { } 2 3 5
elsif ($c =~ /print/i) { } 2 1 3
elsif ($c =~ /null/i) { } 0 1 1
elsif ($c =~ /on/i) { } 0 1 1
elsif ($c =~ /off/i) { } 1 0 1
elsif ($c =~ /truncated/i) { } 0 0 0
elsif ($c =~ /wordwrapped/i) { } 0 0 0
elsif ($c =~ /wrapped/i) { } 0 0 0
652 ########################################################
653 # Alias
654 ########################################################
655 0 $col->{$c} = shift @words;
656 $self->log( "setting alias ... $col->{$c} ..." )
657 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
658 } elsif ( $c =~ m/clear/i ) {
659 ########################################################
660 # Clear: syntax column column_name clear
661 ########################################################
662 0 $self->_clear_format( \$column_format, $command );
663 0 return $self->log( "format cleared" );
664 } elsif ( $c =~ m/fold_after/i ) {
665 ########################################################
666 # Fold After
667 ########################################################
668 } elsif ( $c =~ m/fold_before/i ) {
669 ########################################################
670 # Fold Before
671 ########################################################
672 } elsif ( $c =~ m/format/i ) {
673 ########################################################
674 # Format
675 ########################################################
676 # Begin with format of A# strings, 9 numeric.
677 27 my $f = shift @words;
678 27 ▶ return $self->column_usage( {format => 'undef'} )
Branch: 1 branch
BranchTrueFalseTotal
unless $f 0 27 27
679 unless $f;
680  
681 27 $self->_determine_format( $f, \$col );
682  
683 } elsif ( $c =~ m/heading/i ) {
684 ########################################################
685 # Heading
686 ########################################################
687 22 $col->{$c} = shift @words;
688 $self->log( "setting heading ... $col->{$c} ..." )
689 22 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 22 22
690 } elsif ( $c =~ m/justify/i ) {
691 ########################################################
692 # Justify
693 ########################################################
694 # unset current justification.
695 17 my $f = shift @words;
696 # Handle special conditions.
697 17 ▶ if ($f =~ m/(?:of(?:f)?)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /(?:of(?:f)?)/) 3 14 17
698 3 $col->{$c} = undef;
699 $self->log( "justify cleared ... $f ..." ) if
700 3 ▶ $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 3 3
701 3 next;
702 }
703  
704 14 $col->{$c} = undef;
705  
706 14 foreach my $just (@{$column->{$c}}) {
707 #$self->log( "\ttesting $f $just" ) if $self->{debug};
708 38 ▶ if ($f =~ m/^($just)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /^($just)/i) 10 28 38
709 #$self->log( "\tmatch $f and $just" ) if $self->{debug};
710 10 $col->{$c} = $1;
711 10 last;
712 }
713 }
714 return $self->log( "invalid justification $f" ) unless
715 14 ▶ $col->{$c};
Branch: 1 branch
BranchTrueFalseTotal
unless $col->{$c} 4 10 14
716 $self->log( "setting justify ... $col->{$c} $f ..." )
717 10 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 10 10
718 } elsif ( $c =~ m/like/i ) {
719 ########################################################
720 # Like
721 ########################################################
722 0 $col->{$c} = shift @words;
723 } elsif ( $c =~ m/newline/i ) {
724 ########################################################
725 # Newline
726 ########################################################
727 } elsif ( $c =~ m/new_value/i ) {
728 ########################################################
729 # New Value
730 ########################################################
731 } elsif ( $c =~ m/noprint/i ) {
732 ########################################################
733 # No Print
734 ########################################################
735 2 $col->{$c} = 1;
736 2 $col->{'print'} = 0;
737 $self->log( "setting noprint ... $col->{$c} ..." )
738 2 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 2 2
739 } elsif ( $c =~ m/print/i ) {
740 ########################################################
741 # Print
742 ########################################################
743 2 $col->{$c} = 1;
744 2 $col->{'noprint'} = 0;
745 $self->log( "setting print ... $col->{$c} ..." )
746 2 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 2 2
747 } elsif ( $c =~ m/null/i ) {
748 ########################################################
749 # Null
750 ########################################################
751 0 $col->{$c} = shift @words;
752 $self->log( "setting null text ... $col->{$c} ..." )
753 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
754 } elsif ( $c =~ m/on/i ) {
755 ########################################################
756 # On
757 ########################################################
758 0 $col->{$c} = 1;
759 0 $col->{off} = 0;
760 $self->log( "setting format on ... $col->{$c} ..." )
761 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
762 } elsif ( $c =~ m/off/i ) {
763 ########################################################
764 # Off
765 ########################################################
766 1 $col->{$c} = 1;
767 1 $col->{on} = 0;
768 $self->log( "setting format off ... $col->{$c} ..." )
769 1 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 1 1
770 } elsif ( $c =~ m/truncated/i ) {
771 ########################################################
772 # Truncated
773 ########################################################
774 0 $col->{$c} = 1;
775 0 $col->{'wrapped'} = 0;
776 $self->log( "setting truncated ... $col->{$c} ..." )
777 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
778 } elsif ( $c =~ m/wordwrapped/i ) {
779 ########################################################
780 # Word Wrapped
781 ########################################################
782 $self->log( "setting wordwrapped ... $col->{$c} ..." )
783 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
784 } elsif ( $c =~ m/wrapped/i ) {
785 ########################################################
786 # Wrapped
787 ########################################################
788 0 $col->{$c} = 1;
789 0 $col->{'truncated'} = 0;
790 $self->log( "setting wrapped ... $col->{$c} ..." )
791 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
792 } else {
793 ########################################################
794 # Unknown
795 ########################################################
796 $self->log( "column unknown option: ... $c ..." )
797 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
798 }
799  
800 }
801 }
802 #
803 # At this point the format is defined for the current column, now build
804 # the format string.
805 #
806 {
807 # Default justify is left.
808 29 my $justify = '<';
809  
810 $self->log ("Truncated and Warpped both set for this column: $col->{name}" )
811 if (exists $col->{truncated} and
812 exists $col->{wrapped} and
813 $col->{truncated} and
814 $col->{wrapped}
815 29 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
if exists $col->{"truncated"} and exists $col->{"wrapped"} and $col->{"truncated"} and $col->{"wrapped"} 0 29 29
Condition33%3/9
exists $col->{"truncated"} and exists $col->{"wrapped"} and $col->{"truncated"} and $col->{"wrapped"}
!ll&&!rl&&r
2900
exists $col->{"truncated"} and exists $col->{"wrapped"} and $col->{"truncated"}
!ll&&!rl&&r
0290
exists $col->{"truncated"} and exists $col->{"wrapped"}
!ll&&!rl&&r
0029
MC/DC0%0/4
exists $col->{"truncated"} and exists $col->{"wrapped"} and $col->{"truncated"} and $col->{"wrapped"}
exists $col->{"truncated"} exists $col->{"wrapped"} $col->{"truncated"} $col->{"wrapped"}
Truth table20%1/5
A and B and C and D
A= exists $col->{"truncated"}B= exists $col->{"wrapped"}C= $col->{"truncated"}D= $col->{"wrapped"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
816  
817 29 ▶ $justify = '<' if defined $col->{truncated};
Branch: 1 branch
BranchTrueFalseTotal
if defined $col->{"truncated"} 0 29 29
818 29 ▶ $justify = '[' if defined $col->{wrapped};
Branch: 1 branch
BranchTrueFalseTotal
if defined $col->{"wrapped"} 0 29 29
819  
820 29 ▶ if (defined $col->{'justify'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $col->{"justify"}) 10 19 29
821 10 ▶ if ($col->{'justify'} eq 'l') {
Branch: 3 branches
BranchTrueFalseTotal
if ($col->{'justify'} eq 'l') { } 2 8 10
elsif ($col->{'justify'} eq 'r') { } 5 3 8
elsif ($col->{'justify'} eq 'c') { } 3 0 3
822 $justify =
823 2 ▶ (defined $col->{wrapped} ? '[' : '<');
Branch: 1 branch
BranchTrueFalseTotal
defined $col->{'wrapped'} ? : 0 2 2
824 } elsif ( $col->{'justify'} eq 'r' ) {
825 $justify =
826 5 ▶ (defined $col->{wrapped} ? ']' : '>');
Branch: 1 branch
BranchTrueFalseTotal
defined $col->{'wrapped'} ? : 0 5 5
827 } elsif ( $col->{'justify'} eq 'c' ) {
828 $justify =
829 3 ▶ (defined $col->{wrapped} ? '|' : '^');
Branch: 1 branch
BranchTrueFalseTotal
defined $col->{'wrapped'} ? : 0 3 3
830 } else {
831 $self->log( "unknown justify $col->{'justify'}" )
832 0 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
833 0 $justify = '<';
834 }
835 }
836  
837 # warn "build format for column: " . $command . "\n";
838  
839 29 ▶ unless (defined $col->{'length'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $col->{"length"}) 0 29 29
840 0 $col->{'length'} = length $command;
841 }
842  
843 # Allow for head and column format differences.
844 29 $col_head->{'format'} = $justify x $col->{'length'};
845 29 $col->{'format'} = $justify x $col->{'length'};
846  
847 # foreach my $col (sort keys %{$column_format->{$command}}) {
848 # next unless $column_format->{$command}->{$col};
849 # printf( "\t%-15s %s\n", $col, ($column_format->{$command}->{$col}||'undef') );
850 # }
851  
852 }
853  
854 29 return;
855 }
856  
857 sub column_usage {
858 0 ▶ my ($self, $error ) = @_;
Subroutine column_usage: not called CC=1 SCAR=6.9
Pod undocumented
859 return $self->print_buffer(
860 join( " ",
861 qq{usage column: },
862 0 (map { "$_ is $error->{$_}" } keys %$error ),
863 )
864 );
865 }
866  
867 sub _clear_format {
868 8 ▶ my ($self, $column_formats, $column) = @_;
Subroutine _clear_format: called CC=2 SCAR=7.6
869  
870 # warn "Removing format for : $column :\n";
871  
872 8 ▶ if (exists $$column_formats->{$column}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$column_formats->{$column}) { } 8 0 8
873 # Out of here!
874 8 delete $$column_formats->{$column};
875 # delete $$column_header_format->{$column};
876 } else {
877 # Can clear it, not defined.
878 0 $self->alert( "column clear $column: format not defined." );
879 }
880  
881 }
882  
883  
884 sub _determine_format {
885 27 ▶ my ($self, $format_requested, $mycol) = @_;
Subroutine _determine_format: called CC=21 SCAR=56.5
886  
887 27 my $col = ${$mycol};
888 27 my $numeric = ();
889  
890 # Determine what type of format?
891  
892 27 ▶ if ( $format_requested =~ m/a(\d+)/i ) { # Character
Branch: 3 branches
BranchTrueFalseTotal
if ($format_requested =~ /a(\d+)/i) { } 27 0 27
elsif ($format_requested =~ /^date$/) { } 0 0 0
elsif ($format_requested =~ /(\d+)/) { } 0 0 0
893 27 $col->{'length'} = $1;
894 27 $col->{'type'} = 'char';
895 27 $col->{'format_function'} = undef;
896 } elsif ( $format_requested =~ m/^date$/ ) { # Date
897 0 $col->{'length'} = 8;
898 0 $col->{'type'} = 'date';
899 0 $col->{'format_function'} = undef;
900 } elsif ( $format_requested =~ m/(\d+)/ ) { # Numeric 9's
901 # 999.99
902 # ^^^^^^^^^ ^^^^^
903 # PRECISION SCALE
904  
905 0 $col->{'format_function'} = undef;
906  
907 0 $col->{'type'} = 'numeric';
908  
909 0 my $len = $format_requested =~ tr /[0-9]/[0-9]/;
910 0 ▶ $len++ while($format_requested =~ m/[BSVG\.\$]|MI/ig);
Branch: 1 branch
BranchTrueFalseTotal
$format_requested =~ /[BSVG\.\$]|MI/gi and do { ++$len } 0 0 0
911 0 $len += $format_requested =~ tr/,/,/;
912  
913 # Length is defined as total length of the formatted results.
914 0 $col->{'length'} = $len;
915  
916 # Determine precision and scale:
917 0 my ($p,$s) = (0,0);
918 0 my ($p1,$s1) = split(/\./, $format_requested);
919 0 ▶ $p = $p1 =~ tr /[0-9]/[0-9]/ if $p1;
Branch: 1 branch
BranchTrueFalseTotal
if $p1 0 0 0
920 0 ▶ $s = $s1 =~ tr /[0-9]/[0-9]/ if $s1;
Branch: 1 branch
BranchTrueFalseTotal
if $s1 0 0 0
921  
922 # warn "$format_requested/precision($p)/scale($s)/length($len)\n";
923  
924 0 $col->{'precision'} = $p;
925 0 $col->{'scale'} = $s;
926  
927 # default the commify to NO.
928 0 $col->{'commify'} = 0;
929  
930 # $ $9999
931 0 ▶ if ($format_requested =~ m/\$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format_requested =~ /\$/) 0 0 0
932 # warn "adding function dollarsign\n";
933 0 $col->{'format_function'} = \&dollarsign;
934 }
935  
936 # B B9999
937 0 ▶ $numeric->{B}++ if $format_requested =~ m/B/i;
Branch: 1 branch
BranchTrueFalseTotal
if $format_requested =~ /B/i 0 0 0
938 # MI 9999MI
939 0 ▶ $numeric->{MI}++ if $format_requested =~ m/MI/i;
Branch: 1 branch
BranchTrueFalseTotal
if $format_requested =~ /MI/i 0 0 0
940 # S S9999
941 0 ▶ $numeric->{S}++ if $format_requested =~ m/S/i;
Branch: 1 branch
BranchTrueFalseTotal
if $format_requested =~ /S/i 0 0 0
942 # PR 9999PR
943 0 ▶ $numeric->{PR}++ if $format_requested =~ m/PR/i;
Branch: 1 branch
BranchTrueFalseTotal
if $format_requested =~ /PR/i 0 0 0
944 # D 99D99
945 0 ▶ $numeric->{D}++ if $format_requested =~ m/D/i;
Branch: 1 branch
BranchTrueFalseTotal
if $format_requested =~ /D/i 0 0 0
946 # G 9G999
947 0 ▶ $numeric->{G}++ if $format_requested =~ m/G/i;
Branch: 1 branch
BranchTrueFalseTotal
if $format_requested =~ /G/i 0 0 0
948 # C C999
949 0 ▶ $numeric->{C}++ if $format_requested =~ m/C/i;
Branch: 1 branch
BranchTrueFalseTotal
if $format_requested =~ /C/i 0 0 0
950 # L L999
951 0 ▶ $numeric->{L}++ if $format_requested =~ m/L/i;
Branch: 1 branch
BranchTrueFalseTotal
if $format_requested =~ /L/i 0 0 0
952 # . (period) 99.99
953 0 ▶ $numeric->{period}++ if $format_requested =~ m/\./;
Branch: 1 branch
BranchTrueFalseTotal
if $format_requested =~ /\./ 0 0 0
954 # V 999V99
955 0 ▶ $numeric->{V}++ if $format_requested =~ m/V/i;
Branch: 1 branch
BranchTrueFalseTotal
if $format_requested =~ /V/i 0 0 0
956 # EEEE 9.999EEEE
957 0 ▶ $numeric->{EEEE}++ if $format_requested =~ m/EEEE/i;
Branch: 1 branch
BranchTrueFalseTotal
if $format_requested =~ /EEEE/i 0 0 0
958  
959 # , (comma) 9,999
960 0 ▶ if ($format_requested =~ m/\,/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format_requested =~ /\,/) 0 0 0
961 0 $col->{'commify'} = 1;
962 }
963 } else {
964 0 return $self->column_usage( {format => "$format_requested invalid" });
965 }
966 # Save orignal format value.
967 27 $col->{'column_format'} = $format_requested;
968  
969 $self->log( "setting format ... $col->{'length'} $col->{'type'} ..." )
970 27 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 27 27
971  
972 27 return;
973 }
974  
975 # Document from Oracle 9i SQL*Plus reference.
976 #
977 # FOR[MAT] format
978 #
979 # Specifies the display format of the column. The format specification
980 # must be a text constant such as A10 or $9,999--not a variable.
981 #
982 # Character Columns The default width of CHAR, NCHAR, VARCHAR2 (VARCHAR)
983 # and NVARCHAR2 (NCHAR VARYING) columns is the width of the column in
984 # the database. SQL*Plus formats these datatypes left-justified. If a
985 # value does not fit within the column width, SQL*Plus wraps or
986 # truncates the character string depending on the setting of SET WRAP.
987 #
988 # A LONG, CLOB or NCLOB column's width defaults to the value of SET
989 # LONGCHUNKSIZE or SET LONG, whichever one is smaller.
990 #
991 # To change the width of a datatype to n, use FORMAT An. (A stands for
992 # alphanumeric.) If you specify a width shorter than the column heading,
993 # SQL*Plus truncates the heading. If you specify a width for a LONG,
994 # CLOB, or NCLOB column, SQL*Plus uses the LONGCHUNKSIZE or the
995 # specified width, whichever is smaller, as the column width.
996 #
997 # DATE Columns The default width and format of unformatted DATE columns
998 # in SQL*Plus is derived from the NLS parameters in effect. Otherwise,
999 # the default width is A9. In Oracle9i, the NLS parameters may be set in
1000 # your database parameter file or may be environment variables or an
1001 # equivalent platform-specific mechanism. They may also be specified for
1002 # each session with the ALTER SESSION command. (See the documentation
1003 # for Oracle9i for a complete description of the NLS parameters).
1004 #
1005 # You can change the format of any DATE column using the SQL function
1006 # TO_CHAR in your SQL SELECT statement. You may also wish to use an
1007 # explicit COLUMN FORMAT command to adjust the column width.
1008 #
1009 # When you use SQL functions like TO_CHAR, Oracle automatically allows
1010 # for a very wide column.
1011 #
1012 # To change the width of a DATE column to n, use the COLUMN command with
1013 # FORMAT An. If you specify a width shorter than the column heading, the
1014 # heading is truncated.
1015 #
1016 # NUMBER Columns To change a NUMBER column's width, use FORMAT followed
1017 # by an element as specified in Table 8-1.
1018 #
1019 # Table 8-1 Number Formats
1020 # Element Examples Description
1021 # 9 9999
1022 #
1023 # Number of "9"s specifies number of significant digits returned.
1024 # Blanks are displayed for leading zeroes. A zero (0) is displayed for
1025 # a value of zero.
1026 #
1027 # 0 0999 9990
1028 #
1029 # Displays a leading zero or a value of zero in this position as 0.
1030 #
1031 # $ $9999
1032 #
1033 # Prefixes value with dollar sign.
1034 #
1035 # B B9999
1036 #
1037 # Displays a zero value as blank, regardless of "0"s in the format model.
1038 #
1039 # MI 9999MI
1040 #
1041 # Displays "-" after a negative value. For a positive value, a trailing space is displayed.
1042 #
1043 # S S9999
1044 #
1045 # Returns "+" for positive values and "-" for negative values in this position.
1046 #
1047 # PR 9999PR
1048 #
1049 # Displays a negative value in <angle brackets>. For a positive value,
1050 # a leading and trailing space is displayed.
1051 #
1052 # D 99D99
1053 #
1054 # Displays the decimal character in this position, separating the
1055 # integral and fractional parts of a number.
1056 #
1057 # G 9G999
1058 #
1059 # Displays the group separator in this position.
1060 #
1061 # C C999
1062 #
1063 # Displays the ISO currency symbol in this position.
1064 #
1065 # L L999
1066 #
1067 # Displays the local currency symbol in this position.
1068 #
1069 # , (comma) 9,999
1070 #
1071 # Displays a comma in this position.
1072 #
1073 # . (period) 99.99
1074 #
1075 # Displays a period (decimal point) in this position, separating the
1076 # integral and fractional parts of a number.
1077 #
1078 # V 999V99
1079 #
1080 # Multiplies value by 10n, where n is number of "9"s after "V".
1081 #
1082 # EEEE 9.999EEEE
1083 #
1084 # Displays value in scientific notation (format must contain exactly four "E"s).
1085 #
1086 # RN or rn RN
1087 #
1088 # Displays upper- or lowercase Roman numerals. Value can be an integer between 1 and 3999.
1089 #
1090 # DATE DATE
1091 #
1092 # Displays value as a date in MM/DD/YY format; used to format NUMBER
1093 # columns that represent Julian dates.
1094 #
1095 #
1096 #
1097 # The MI and PR format elements can only appear in the last position of
1098 # a number format model. The S format element can only appear in the
1099 # first or last position.
1100 #
1101 # If a number format model does not contain the MI, S or PR format
1102 # elements, negative return values automatically contain a leading
1103 # negative sign and positive values automatically contain a
1104 # leading space.
1105 #
1106 # A number format model can contain only a single decimal character (D)
1107 # or period (.), but it can contain multiple group separators (G) or
1108 # commas (,). A group separator or comma cannot appear to the right of a
1109 # decimal character or period in a number format model.
1110 #
1111 # SQL*Plus formats NUMBER data right-justified. A NUMBER column's width
1112 # equals the width of the heading or the width of the FORMAT plus one
1113 # space for the sign, whichever is greater. If you do not explicitly use
1114 # FORMAT, then the column's width will always be at least the value of
1115 # SET NUMWIDTH.
1116 #
1117 # SQL*Plus may round your NUMBER data to fit your format or field width.
1118 #
1119 # If a value cannot fit within the column width, SQL*Plus indicates
1120 # overflow by displaying a pound sign (#) in place of each digit the
1121 # width allows.
1122 #
1123 # If a positive value is extremely large and a numeric overflow occurs
1124 # when rounding a number, then the infinity sign (~) replaces the value.
1125 # Likewise, if a negative value is extremely small and a numeric
1126 # overflow occurs when rounding a number, then the negative infinity
1127 # sign replaces the value (-~).
1128  
1129 # Commify used from the Perl CookBook
1130 sub commify($) {
1131 0 ▶ my $num = reverse $_[0];
Subroutine commify: not called CC=1 SCAR=6.9
Pod undocumented
1132 0 $num =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
1133 0 return scalar reverse $num;
1134 }
1135  
1136 sub dollarsign($$$$) {
1137 0 ▶ my ($num, $fmtnum, $dlen, $commify) = @_;
Subroutine dollarsign: not called CC=2 SCAR=17.9
Pod undocumented
1138 0 my $formatted = sprintf "\$%${fmtnum}.${dlen}lf", $num;
1139 0 ▶ return ($commify ? commify($formatted) : $formatted);
Branch: 1 branch
BranchTrueFalseTotal
$commify ? : 0 0 0
1140 }
1141  
1142 sub zerofill($$$$) {
1143 0 ▶ my ($num, $fmtnum, $dlen, $commify) = @_;
Subroutine zerofill: not called CC=2 SCAR=17.9
Pod undocumented
1144 0 my $formatted = sprintf "%0${fmtnum}.${dlen}lf", $num;
1145 0 ▶ return ($commify ? commify($formatted) : $formatted);
Branch: 1 branch
BranchTrueFalseTotal
$commify ? : 0 0 0
1146 }
1147  
1148 sub signednum($$$$) {
1149 0 ▶ my ($num, $fmtnum, $dlen, $commify) = @_;
Subroutine signednum: not called CC=2 SCAR=17.9
Pod undocumented
1150 0 my $formatted = sprintf "%+${fmtnum}.${dlen}lf", $num;
1151 0 ▶ return ($commify ? commify($formatted) : $formatted);
Branch: 1 branch
BranchTrueFalseTotal
$commify ? : 0 0 0
1152 }
1153  
1154 sub leadsign($$$$) {
1155 0 ▶ my ($num, $fmtnum, $dlen, $commify) = @_;
Subroutine leadsign: not called CC=2 SCAR=17.9
Pod undocumented
1156 0 my $formatted = sprintf "%+${fmtnum}.${dlen}lf", $num;
1157 0 ▶ return ($commify ? commify($formatted) : $formatted);
Branch: 1 branch
BranchTrueFalseTotal
$commify ? : 0 0 0
1158 }
1159  
1160 sub trailsign($$$$) {
1161 0 ▶ my ($num, $fmtnum, $dlen, $commify) = @_;
Subroutine trailsign: not called CC=3 SCAR=24.8
Pod undocumented
1162 0 $dlen--;
1163 0 my $formatted = sprintf "%${fmtnum}.${dlen}lf", abs($num);
1164 0 ▶ $formatted .= ($num > 0 ? '+' : '-');
Branch: 1 branch
BranchTrueFalseTotal
$num > 0 ? : 0 0 0
1165 0 ▶ return ($commify ? commify($formatted) : $formatted);
Branch: 1 branch
BranchTrueFalseTotal
$commify ? : 0 0 0
1166 }
1167  
1168 sub ltgtsign($$$$) {
1169 0 ▶ my ($num, $fmtnum, $dlen, $commify) = @_;
Subroutine ltgtsign: not called CC=4 SCAR=30.0
Pod undocumented
1170 0 $dlen--;
1171 0 ▶ my $formatted = sprintf "%s%${fmtnum}.${dlen}lf%s"
Branch: 2 branches
BranchTrueFalseTotal
$num > 0 ? : 0 0 0
$num > 0 ? : 0 0 0
1172 ,($num > 0 ? '' : '<')
1173 ,abs($num),
1174 ,($num > 0 ? '' : '>');
1175 0 ▶ return ($commify ? commify($formatted) : $formatted);
Branch: 1 branch
BranchTrueFalseTotal
$commify ? : 0 0 0
1176 }
1177  
1178 #
1179 # Private methods.
1180 #
1181  
1182 sub _me {
1183 0 ▶ my $pi = shift;
Subroutine _me: not called CC=2 SCAR=17.9
1184 0 my $self = shift;
1185 0 ▶ return ${$self}->print_buffer("show me what???")
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
1186 unless @_;
1187 0 return ${$self}->do_show(@_);
1188 }
1189  
1190 sub _all {
1191 0 ▶ my $pi = shift;
Subroutine _all: not called CC=2 SCAR=17.9
1192 0 my $self = shift;
1193 0 ▶ return ${$self}->print_buffer("show all of what???")
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
1194 unless @_;
1195 0 return ${$self}->do_show(@_);
1196 }
1197  
1198 sub _show_all_commands {
1199 0 ▶ my $pi = shift;
Subroutine _show_all_commands: not called CC=1 SCAR=6.9
1200 0 my $self = shift;
1201 return
1202 0 ${$self}->print_buffer("Show supports the following commands:\n\t" .
1203 0 join( "\n\t", keys %{$pi->{show}}));
1204 }
1205  
1206 sub _unimp {
1207 0 ▶ my $pi = shift;
Subroutine _unimp: not called CC=1 SCAR=6.9
1208 0 my $self = shift;
1209 0 return ${$self}->print_buffer("unimplemented");
1210 }
1211  
1212 sub _obsolete {
1213 0 ▶ my $pi = shift;
Subroutine _obsolete: not called CC=1 SCAR=6.9
1214 0 my $self = shift;
1215 0 return ${$self}->print_buffer("obsolete: use " . join( " ", @_) );
1216 }
1217  
1218 sub _print_buffer {
1219 0 ▶ my $pi = shift;
Subroutine _print_buffer: not called CC=1 SCAR=6.9
1220 0 my $self = shift;
1221 0 return ${$self}->print_buffer(@_);
1222 }
1223  
1224 sub _set_get {
1225 24 ▶ my $pi = shift;
Subroutine _set_get: called CC=6 SCAR=18.4
1226 24 my $self = shift;
1227 24 my $command = shift;
1228  
1229 24 ▶ carp "command undefined: " and return unless defined $command;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $command 0 24 24
Condition20%1/5
defined $command || carp('command undefined: ') && (return)
l!l&&r!l&&!r
2400
carp("command undefined: ") and return
!ll
00
MC/DC0%0/2
defined $command || carp('command undefined: ') && (return)
defined $command carp("command undefined: ")
Truth table33%1/3
A || B
A= defined $commandB= carp("command undefined: ")
ABresult
1X1
011
000
1230  
1231 # Use the off to undefine/null a value.
1232 24 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 21 3 24
1233 21 my $val = shift;
1234 21 ▶ if ($val =~ m/off/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /off/i) { } 6 15 21
1235 6 $pi->{set_current}->{$command} = undef;
1236 } else {
1237 15 $pi->{set_current}->{$command} = $val
1238 }
1239  
1240 }
1241 24 ▶ ${$self}->print_buffer(
Condition100%2/2
$pi->{'set_current'}{$command} || 'null'
l!l
177
MC/DC100%1/1
$pi->{'set_current'}{$command} || 'null'
$pi->{'set_current'}{$command}
Truth table100%2/2
A
A= $pi->{'set_current'}{$command}
Aresult
11
00
1242 24 qq{$command: } . ($pi->{set_current}->{$command}||
1243 'null')
1244 );
1245 24 return $pi->{set_current}->{$command};
1246 }
1247  
1248 #------------------------------------------------------------------
1249 #
1250 # Display a list of all schemas.
1251 #
1252 #------------------------------------------------------------------
1253 sub _schemas {
1254 0 ▶ my ($pi, $sh, @args) = @_;
Subroutine _schemas: not called CC=2 SCAR=17.9
1255 #
1256 # Allow types to accept a list of types to display.
1257 #
1258 0 my $sth;
1259  
1260 0 my $dbh = ${$sh}->{dbh};
1261 0 $sth = $dbh->table_info('', '%', '', '');
1262  
1263 0 ▶ unless(ref $sth) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $sth) 0 0 0
1264 0 ${$sh}->log( "Advance table_info not supported\n");
1265 0 return;
1266 }
1267 0 return ${$sh}->sth_go($sth, 0, 0);
1268 }
1269  
1270 #------------------------------------------------------------------
1271 #
1272 # Display the last sql code, error, and error string.
1273 #
1274 #------------------------------------------------------------------
1275 sub _sqlcode {
1276 1 ▶ my ($pi, $sh, @args) = @_;
Subroutine _sqlcode: called CC=6 SCAR=18.8
1277  
1278 1 my $dbh = ${$sh}->{dbh};
1279  
1280 1 my $codes;
1281
1282 1 ▶ $codes .= "last dbi error : " . $dbh->err . "\n" if $dbh->err;
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->err 1 0 1
1283 1 ▶ $codes .= "last dbi error string : " . $dbh->errstr . "\n" if $dbh->err;
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->err 1 0 1
1284 1 ▶ $codes .= "last dbi error state : " . $dbh->state . "\n" if $dbh->err;
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->err 1 0 1
1285  
1286 1 ▶ ${$sh}->print_buffer_nop( $codes ) if defined $codes;
Branch: 1 branch
BranchTrueFalseTotal
if defined $codes 1 0 1
1287  
1288 1 ▶ return $dbh->err||0;
Condition50%1/2
$dbh->err || 0
l!l
10
MC/DC0%0/1
$dbh->err || 0
$dbh->err
Truth table50%1/2
A
A= $dbh->err
Aresult
11
00
1289 }
1290  
1291 #------------------------------------------------------------------
1292 #
1293 # Display a list of all tables.
1294 #
1295 #------------------------------------------------------------------
1296 sub _tables {
1297 0 ▶ my ($pi, $sh, @args) = @_;
Subroutine _tables: not called CC=1 SCAR=6.9
1298 0 return $pi->_sup_types( $sh, 'TABLE', @args );
1299 }
1300  
1301 #------------------------------------------------------------------
1302 #
1303 # Display a list of all types.
1304 #
1305 #------------------------------------------------------------------
1306 sub _types {
1307 0 ▶ my ($pi, $sh, @args) = @_;
Subroutine _types: not called CC=3 SCAR=24.8
1308 #
1309 # Allow types to accept a list of types to display.
1310 #
1311 0 my $sth;
1312 0 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
1313 0 return $pi->_sup_types( $sh, @args );
1314 }
1315  
1316 0 my $dbh = ${$sh}->{dbh};
1317 0 $sth = $dbh->table_info('', '', '', '%');
1318  
1319 0 ▶ unless(ref $sth) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $sth) 0 0 0
1320 0 ${$sh}->log( "Advance table_info not supported\n" );
1321 0 return;
1322 }
1323 0 return ${$sh}->sth_go($sth, 0, 0);
1324 }
1325  
1326 #------------------------------------------------------------------
1327 #
1328 # Display a list of all views.
1329 #
1330 #------------------------------------------------------------------
1331 sub _views {
1332 0 ▶ my ($pi, $sh, @args) = @_;
Subroutine _views: not called CC=1 SCAR=6.9
1333  
1334 0 return $pi->_sup_types( $sh, 'VIEW', @args );
1335 }
1336  
1337 #------------------------------------------------------------------
1338 #
1339 # Handle different types.
1340 #
1341 #------------------------------------------------------------------
1342 sub _sup_types {
1343 0 ▶ my ($pi, $sh, $type, @args) = @_;
Subroutine _sup_types: not called CC=4 SCAR=30.0
1344  
1345 0 $sh = ${$sh}; # Need to dereference the shell object.
1346  
1347 0 my $dbh = $sh->{dbh};
1348  
1349 0 ▶ return unless (defined $type);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 0 0
1350  
1351 0 my $sth;
1352 0 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 0 0 0
1353 0 my $tbl = join( ",", @args );
1354 0 $sth = $dbh->table_info(undef, undef, $tbl, $type);
1355 } else {
1356 0 $sth = $dbh->table_info(undef, undef, undef, $type);
1357 }
1358  
1359 0 ▶ unless (ref $sth) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $sth) 0 0 0
1360 0 ${$sh}->log( "Advance table_info not supported\n" );
1361 0 return;
1362 }
1363  
1364 0 return $sh->sth_go($sth, 0, 0);
1365 }
1366  
1367 4 1;
1368  
1369  
↑ Summary blib/lib/DBI/Shell.pm »