blib/lib/blx/xsdsql/generator/sql/DBM/handle/insert_dictionary.pm untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 86 CC 10 SCAR 28.4
CC
10
Cov
0%
_manip_value
30.0
_get_table_columns_data
20.0
_get_next_sequence
12.0
CRAP 17.1
1 package blx::xsdsql::generator::sql::DBM::handle::insert_dictionary;
2 use strict; # use strict is for PBP
3 use Filter::Include;
4 include blx::xsdsql::include;
5 #line 6
6  
7 use blx::xsdsql::ut::ut qw(nvl);
8 use base qw(blx::xsdsql::generator::sql::generic::handle::insert_dictionary);
9  
10 sub _manip_value { #manip values from input data
11 my ($self,$col,$value,%params)=@_;
12 if (defined $value) {
13 my $t=$col->get_attrs_value(qw(TYPE_DUMPER));
14 affirm { defined $t } "attribute TYPE_DUMPER not set for column ".nvl($col->get_full_name);
15 if ($t->{BASE} eq 'boolean') {
16 if ($value eq '1') {
17 $value='Y' ;
18 }
19 elsif($value eq '0') {
20 $value=undef;
21 }
22 else {
23 croak "'$value': unknow value for type boolean"
24 }
25 }
26 }
27 return $self->SUPER::_manip_value($col,$value,%params);
28 }
29  
30 {
31 my $counter=0;
32 sub _get_next_sequence {
33 my ($self,%params)=@_;
34 return ++$counter if $counter;
35 local $@;
36 my $n=eval {
37 local $self->{BINDING}->get_attrs_value(qw(DB_CONN))->{PrintError};
38 $self->{BINDING}->get_next_sequence
39 };
40 $@ ? ++$counter : $n;
41 }
42 }
43  
44 sub _get_table_columns_data {
45 my ($self,$extra_tables,$table,$type,%params)=@_;
46 my $dic=$extra_tables->{$type};
47 affirm { defined $dic } "'$type': wrong table type";
48 my $data=$self->_get_table_data($table,$type,%params);
49 my $columns=$self->_get_dictionary_columns($dic);
50 if ($columns->[0]->get_attrs_value(qw(PK_AUTOSEQUENCE))) {
51 affirm { !defined $self->{SQL_BINDING} } "attribute SQL_BINDING is obsolete";
52 affirm { defined $self->{BINDING} } "attribute BINDING not set";
53 unless ( defined $self->{BINDING}->get_attrs_value(qw(SEQUENCE_NAME))) {
54 affirm { defined $self->{EXTRA_TABLES} } "attribute EXTRA_TABLES not set";
55 my $extra_tables=$self->{EXTRA_TABLES};
56 my $seq_name=$extra_tables->get_sequence_name;
57 $self->{BINDING}->set_attrs_value(SEQUENCE_NAME => $seq_name);
58 affirm { defined $self->{BINDING}->get_attrs_value(qw(SEQUENCE_NAME)) } "binding object not has attribute SEQUENCE_NAME set";
59 }
60 if (ref($data) eq 'ARRAY') {
61 for my $d(@$data) {
62 $d->{'$PK'}=$self->_get_next_sequence;
63 }
64 }
65 else {
66 $data->{'$PK'}=$self->_get_next_sequence;
67 }
68 }
69 return ($columns,$data);
70 }
71  
72 1;
73  
74 __END__