lib/CellBIS/SQL/Abstract/Table.pm

filter: Statementstmt 85.2% 225 / 264 Branchbran 65.1% 86 / 132 Conditioncond 40.4% 19 / 47 MC/DCmcdc 19.3% 6 / 31 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 7 totaltotal 70.3% 347 / 493 CC 83 SCAR 31.0
CC
83
Cov
74%
create_colAttr
37.3
create_query_table
24.5
fk_validator
22.0
CRAP 22.3
« blib/lib/CellBIS/SQL/Abstract/Test.pm ↑ Summary lib/CellBIS/SQL/Abstract/Util.pm »
1 package # hide from PAUSE
2 CellBIS::SQL::Abstract::Table;
3 17 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 17 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use Mojo::Util qw(trim);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use Hash::MultiValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 17 has 'db_type' => 'mariadb';
10  
11 # For Foreign Key Validator:
12 # ------------------------------------------------------------------------
13 4 ▶sub fk_validator {
Subroutine fk_validator: called CC=11 SCAR=30.9
Pod undocumented
14 4 my ($table_attr, $col_attr) = @_;
15 4 my %fk_attr = (name => 0, col_name => 0, table_target => 0, col_target => 0,);
16  
17 4 my $fk = $table_attr->{fk};
18 4 ▶ if (exists $fk->{name} && $fk->{name} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fk->{"name"} and $fk->{"name"} ne "") 4 0 4
Condition33%1/3
exists $fk->{"name"} and $fk->{"name"} ne ""
!ll&&!rl&&r
004
MC/DC0%0/2
exists $fk->{"name"} and $fk->{"name"} ne ""
exists $fk->{"name"} $fk->{"name"} ne ""
Truth table33%1/3
A and B
A= exists $fk->{"name"}B= $fk->{"name"} ne ""
ABresult
0X0
100
111
19 4 $fk_attr{name} = 1;
20 }
21 4 ▶ if (exists $fk->{col_name} && $fk->{col_name} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fk->{"col_name"} and $fk->{"col_name"} ne "") 4 0 4
Condition33%1/3
exists $fk->{"col_name"} and $fk->{"col_name"} ne ""
!ll&&!rl&&r
004
MC/DC0%0/2
exists $fk->{"col_name"} and $fk->{"col_name"} ne ""
exists $fk->{"col_name"} $fk->{"col_name"} ne ""
Truth table33%1/3
A and B
A= exists $fk->{"col_name"}B= $fk->{"col_name"} ne ""
ABresult
0X0
100
111
22 4 $fk_attr{col_name} = 1;
23 }
24  
25 4 ▶ if (exists $fk->{table_target} && $fk->{table_target} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fk->{"table_target"} and $fk->{"table_target"} ne "") 4 0 4
Condition33%1/3
exists $fk->{"table_target"} and $fk->{"table_target"} ne ""
!ll&&!rl&&r
004
MC/DC0%0/2
exists $fk->{"table_target"} and $fk->{"table_target"} ne ""
exists $fk->{"table_target"} $fk->{"table_target"} ne ""
Truth table33%1/3
A and B
A= exists $fk->{"table_target"}B= $fk->{"table_target"} ne ""
ABresult
0X0
100
111
26 4 $fk_attr{table_target} = 1;
27 }
28  
29 4 ▶ if (exists $fk->{col_target} && $fk->{col_target} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fk->{"col_target"} and $fk->{"col_target"} ne "") 4 0 4
Condition33%1/3
exists $fk->{"col_target"} and $fk->{"col_target"} ne ""
!ll&&!rl&&r
004
MC/DC0%0/2
exists $fk->{"col_target"} and $fk->{"col_target"} ne ""
exists $fk->{"col_target"} $fk->{"col_target"} ne ""
Truth table33%1/3
A and B
A= exists $fk->{"col_target"}B= $fk->{"col_target"} ne ""
ABresult
0X0
100
111
30 4 $fk_attr{col_target} = 1;
31 }
32 4 my @r_val = grep { !$_ } values %fk_attr;
33 4 my $size_result = scalar @r_val;
34  
35 4 ▶ if ($size_result >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size_result >= 1) { } 0 4 4
36 0 my $new_TableAttr = Hash::MultiValue->new(%{$table_attr});
37 0 $new_TableAttr->remove('fk');
38 0 $table_attr = $new_TableAttr->as_hashref;
39 }
40 else {
41 4 ▶ unless (exists $col_attr->{$fk->{col_name}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$col_attr{$fk->{"col_name"}}) 0 4 4
42 0 my $new_TableAttr = Hash::MultiValue->new(%{$table_attr});
43 0 $new_TableAttr->remove('fk');
44 0 $table_attr = $new_TableAttr->as_hashref;
45 }
46 }
47 4 return $table_attr;
48 }
49  
50 # For Foreign key attribute :
51 # ------------------------------------------------------------------------
52 4 ▶sub fk_attr_validator {
Subroutine fk_attr_validator: called CC=6 SCAR=18.4
Pod undocumented
53 4 my ($fk_table) = @_;
54 4 my $data = '';
55 4 my %ondelup = ('cascade' => 'CASCADE', 'null' => 'SET NULL',
56 'default' => 'SET DEFAULT');
57 4 my $ondel = 0;
58 4 ▶ if (exists $fk_table->{ondelete}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fk_table->{"ondelete"}) 4 0 4
59 4 ▶ if (exists $ondelup{(lc $fk_table->{ondelete})}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ondelup{lc $fk_table->{"ondelete"}}) 4 0 4
60 4 $ondel = 1;
61 4 $data .= 'ON DELETE ' . $ondelup{(lc $fk_table->{ondelete})};
62 }
63 }
64  
65 4 ▶ if (exists $fk_table->{onupdate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fk_table->{"onupdate"}) 4 0 4
66 4 ▶ if (exists $ondelup{(lc $fk_table->{onupdate})}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ondelup{lc $fk_table->{"onupdate"}}) 4 0 4
67 4 ▶ $data .= ' ' if $ondel == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $ondel == 1 4 0 4
68 4 $data .= 'ON UPDATE ' . $ondelup{(lc $fk_table->{onupdate})};
69 }
70 }
71 4 $data = trim($data);
72 4 return $data;
73 }
74  
75 # For Table Attribute Validator :
76 # ------------------------------------------------------------------------
77 10 ▶sub table_attr_val {
Subroutine table_attr_val: called CC=17 SCAR=30.8
Pod undocumented
78 10 my $self = shift;
79 10 my ($col_attr, $table_attr) = @_;
80 10 my $new_tblAttr = {};
81 10 my $attrib_table = '';
82 10 ▶ my $db_type = $self->db_type // 'mariadb';
Condition50%1/2
$self->db_type // "mariadb"
l!l
100
MC/DC0%0/1
$self->db_type // "mariadb"
$self->db_type
Truth table50%1/2
A
A= $self->db_type
Aresult
11
00
83  
84 10 ▶ if (exists $table_attr->{fk}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $table_attr->{"fk"}) 4 6 10
85 4 $table_attr = fk_validator($table_attr, $col_attr);
86 4 my $table_fk = '';
87 4 ▶ if (exists $table_attr->{fk}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $table_attr->{"fk"}) 4 0 4
88 4 my $fk_table = $table_attr->{fk};
89 4 my $fk_name = $fk_table->{name};
90 4 my $col_name = $fk_table->{col_name};
91 4 my $table_target = $fk_table->{table_target};
92 4 my $col_target = $fk_table->{col_target};
93 4 my $fk_attr = '';
94 4 ▶ if ($fk_table->{attr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fk_table->{"attr"}) 4 0 4
95 4 $fk_attr = fk_attr_validator($fk_table->{attr});
96 }
97 4 ▶ if ($db_type eq 'sqlite') {
Branch: 1 branch
BranchTrueFalseTotal
if ($db_type eq 'sqlite') { } 2 2 4
98 2 $table_fk .= "\tCONSTRAINT $fk_name ";
99 2 $table_fk .= "FOREIGN KEY ($col_name) ";
100 2 ▶ $table_fk .= "REFERENCES $table_target ($col_target)\n"
Branch: 1 branch
BranchTrueFalseTotal
if $fk_attr eq "" 0 2 2
101 if $fk_attr eq '';
102 2 ▶ $table_fk .= "REFERENCES $table_target ($col_target) \n\t$fk_attr\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $fk_attr eq "" 2 0 2
103 unless $fk_attr eq '';
104 }
105 else {
106 2 ▶ $table_fk .= "\tKEY " . $fk_name . " ($col_name), \n"
Branch: 1 branch
BranchTrueFalseTotal
if $db_type eq "mariadb" 1 1 2
107 if $db_type eq 'mariadb';
108 2 $table_fk .= "\tCONSTRAINT $fk_name ";
109 2 $table_fk .= "FOREIGN KEY ($col_name) ";
110 2 ▶ $table_fk .= "REFERENCES $table_target ($col_target)\n"
Branch: 1 branch
BranchTrueFalseTotal
if $fk_attr eq "" 0 2 2
111 if $fk_attr eq '';
112 2 ▶ $table_fk .= "REFERENCES $table_target ($col_target) \n\t$fk_attr\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $fk_attr eq "" 2 0 2
113 unless $fk_attr eq '';
114 }
115  
116 4 my $new_attrTbl = Hash::MultiValue->new(%{$table_attr});
117 4 $new_attrTbl->set(fk => $table_fk);
118 4 $table_attr = $new_attrTbl->as_hashref;
119 }
120 }
121 10 ▶ if (exists $table_attr->{index}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $table_attr->{"index"}) 0 10 10
122 0 ▶ if (ref($table_attr->{index}) eq "ARRAY"
Branch: 1 branch
BranchTrueFalseTotal
if (ref $table_attr->{"index"} eq "ARRAY" and scalar @{$table_attr->{"index"};} > 0) 0 0 0
Condition0%0/3
ref $table_attr->{"index"} eq "ARRAY" and scalar @{$table_attr->{"index"};} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $table_attr->{"index"} eq "ARRAY" and scalar @{$table_attr->{"index"};} > 0
ref $table_attr->{"index"} eq "ARRAY" scalar @{$table_attr->{"index"};} > 0
Truth table0%0/3
A and B
A= ref $table_attr->{"index"} eq "ARRAY"B= scalar @{$table_attr->{"index"};} > 0
ABresult
0X0
100
111
123 0 and (scalar @{$table_attr->{index}}) > 0)
124 {
125 0 my $table_index = join ',', @{$table_attr->{index}};
126 0 $table_index = 'INDEX (' . $table_index . ')';
127 0 my $new_attrTbl = Hash::MultiValue->new(%{$table_attr});
128 0 $new_attrTbl->set(index => $table_index);
129 0 $table_attr = $new_attrTbl->as_hashref;
130 }
131 }
132 10 my $engine = 0;
133 10 ▶ if (exists $table_attr->{engine}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $table_attr->{"engine"}) 3 7 10
134 3 $engine = 1;
135 3 my $r_engine = $self->_check_engine($table_attr->{engine});
136 3 $attrib_table .= 'ENGINE=' . $r_engine;
137 }
138 10 ▶ $attrib_table .= ' ' if ($engine == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $engine == 1 3 7 10
139 $attrib_table
140 .= exists $table_attr->{charset}
141 ? 'DEFAULT CHARSET=' . $table_attr->{charset}
142 10 ▶ : 'DEFAULT CHARSET=utf8';
Branch: 1 branch
BranchTrueFalseTotal
exists $table_attr->{'charset'} ? : 2 8 10
143 10 $new_tblAttr = Hash::MultiValue->new(%{$table_attr});
144 10 $new_tblAttr->set(attr => $attrib_table);
145 10 $table_attr = $new_tblAttr->as_hashref;
146  
147 10 return $table_attr;
148 }
149  
150 # For Column Attribute validator :
151 # ------------------------------------------------------------------------
152 10 ▶sub table_col_attr_val {
Subroutine table_col_attr_val: called CC=9 SCAR=22.0
Pod undocumented
153 10 my $self = shift;
154 10 my ($col_list, $col_attr) = @_;
155  
156 10 ▶ if (ref($col_attr) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $col_attr eq "HASH") 10 0 10
157 10 my $i = 0;
158 10 my $until = scalar @{$col_list};
159 10 my @pk_list = ();
160 10 my @ai_list = ();
161 10 my $size_pk = 0;
162 10 my $size_ai = 0;
163 10 my $col_name = '';
164 10 my $curr_colAttr = {};
165 10 my $new_colAttr = Hash::MultiValue->new(%{$col_attr});
166  
167 10 ▶ while ($i < $until) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $until) 47 10 57
168 47 $col_name = $col_attr->{$col_list->[$i]};
169 47 ▶ if (exists $col_name->{'is_autoincre'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $col_name->{"is_autoincre"}) 9 38 47
170 9 $size_ai = ($size_ai + 1);
171 9 push @ai_list, $col_list->[$i];
172 9 $curr_colAttr = Hash::MultiValue->new(%{$col_name});
173 9 $curr_colAttr->remove('is_autoincre');
174  
175 9 $new_colAttr->set($col_list->[$i] => $curr_colAttr->as_hashref);
176 }
177 47 $i++;
178 }
179 10 $col_attr = $new_colAttr->as_hashref;
180  
181 10 $i = 0;
182 10 ▶ while ($i < $until) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $until) 47 10 57
183 47 $col_name = $col_attr->{$col_list->[$i]};
184 47 ▶ if (exists $col_name->{'is_primarykey'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $col_name->{"is_primarykey"}) 10 37 47
185 10 $size_pk = ($size_pk + 1);
186 10 push @pk_list, $col_list->[$i];
187 10 $curr_colAttr = Hash::MultiValue->new(%{$col_name});
188 10 $curr_colAttr->remove('is_primarykey');
189  
190 10 $new_colAttr->set($col_list->[$i] => $curr_colAttr->as_hashref);
191 }
192 47 $i++;
193 }
194  
195 10 ▶ if ($size_pk >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size_pk >= 1) 10 0 10
196 10 my $r_colAttr = $new_colAttr->as_hashref;
197 10 my $pk_table = $r_colAttr->{$pk_list[0]};
198  
199 10 $curr_colAttr = Hash::MultiValue->new(%{$pk_table});
200 10 $curr_colAttr->set('is_primarykey' => 1);
201  
202 10 $col_attr = Hash::MultiValue->new(%{$r_colAttr});
203 10 $col_attr->set($pk_list[0] => $curr_colAttr->as_hashref);
204 10 $col_attr = $col_attr->as_hashref;
205 }
206  
207 10 ▶ if ($size_ai >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size_ai >= 1) 9 1 10
208 9 my $pk_table = $col_attr->{$pk_list[0]};
209  
210 9 $curr_colAttr = Hash::MultiValue->new(%{$pk_table});
211 9 $curr_colAttr->set('is_autoincre' => 1);
212  
213 9 $col_attr = Hash::MultiValue->new(%{$col_attr});
214 9 $col_attr->set($pk_list[0] => $curr_colAttr->as_hashref);
215 9 $col_attr = $col_attr->as_hashref;
216 }
217  
218 10 $i = 0;
219 10 $new_colAttr = Hash::MultiValue->new();
220 10 ▶ while ($i < $until) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $until) 47 10 57
221 47 $col_name = $col_attr->{$col_list->[$i]};
222  
223 47 $new_colAttr->add($col_list->[$i] => $col_name);
224 47 $i++;
225 }
226 10 $col_attr = $new_colAttr->as_hashref;
227 }
228 10 return $col_attr;
229 }
230  
231 # For Default field table :
232 # ------------------------------------------------------------------------
233 0 ▶sub default_field_tbl_val {
Subroutine default_field_tbl_val: not called CC=4 SCAR=30.0
Pod undocumented
234 0 my ($type, $attr) = @_;
235 0 my $data = '';
236 0 ▶ if ($type eq 'datetime') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "datetime") 0 0 0
237 0 ▶ if ($attr == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr == 1) 0 0 0
238 0 $data = "CURRENT_TIMESTAMP";
239 }
240 0 ▶ if ($attr eq 'yes') {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr eq "yes") 0 0 0
241 0 $data = "CURRENT_TIMESTAMP";
242 }
243 }
244 0 return $data;
245 }
246  
247 # For Create Column Attr :
248 # ------------------------------------------------------------------------
249 47 ▶sub create_colAttr {
Subroutine create_colAttr: called CC=21 SCAR=36.2
Pod undocumented
250 47 my $self = shift;
251 47 my ($col_name, $attr, $db_type) = @_;
252 47 my $data = $col_name . ' ';
253  
254 47 ▶ if (exists $attr->{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{"type"}) 47 0 47
255 47 ▶ if ($db_type eq 'sqlite') {
Branch: 1 branch
BranchTrueFalseTotal
if ($db_type eq 'sqlite') { } 33 14 47
256 $data
257 .= exists $attr->{type}->{name}
258 33 ▶ ? (uc $attr->{type}->{name}) . ' '
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{'type'}{'name'} ? : 33 0 33
259 : 'varchar ';
260 }
261 else {
262 $data
263 .= exists $attr->{type}->{name}
264 ? (uc $attr->{type}->{name})
265 14 ▶ : 'varchar';
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{'type'}{'name'} ? : 14 0 14
266 $data
267 .= exists $attr->{type}->{size}
268 14 ▶ ? '(' . $attr->{type}->{size} . ') '
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{'type'}{'size'} ? : 13 1 14
269 : ' ';
270 }
271 }
272  
273 47 ▶ unless (exists $attr->{custom}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $attr->{"custom"}) 47 0 47
274 47 ▶ if (exists $attr->{default} and $attr->{default} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{"default"} and $attr->{"default"} ne "") 0 47 47
Condition33%1/3
exists $attr->{"default"} and $attr->{"default"} ne ""
!ll&&!rl&&r
4700
MC/DC0%0/2
exists $attr->{"default"} and $attr->{"default"} ne ""
exists $attr->{"default"} $attr->{"default"} ne ""
Truth table33%1/3
A and B
A= exists $attr->{"default"}B= $attr->{"default"} ne ""
ABresult
0X0
100
111
275 0 ▶ if (exists $attr->{onupdate} and $attr->{onupdate} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{'onupdate'} and $attr->{'onupdate'} ne '') { } 0 0 0
Condition0%0/3
exists $attr->{"onupdate"} and $attr->{"onupdate"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
exists $attr->{"onupdate"} and $attr->{"onupdate"} ne ""
exists $attr->{"onupdate"} $attr->{"onupdate"} ne ""
Truth table0%0/3
A and B
A= exists $attr->{"onupdate"}B= $attr->{"onupdate"} ne ""
ABresult
0X0
100
111
276 my $field_default_val
277 0 = default_field_tbl_val($attr->{type}->{name}, $attr->{onupdate});
278 0 $data .= "ON UPDATE $field_default_val ";
279 }
280 else {
281 0 $data .= "DEFAULT $attr->{default} ";
282 }
283 }
284  
285 47 ▶ if (exists $attr->{onupdate} and $attr->{onupdate} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{"onupdate"} and $attr->{"onupdate"} ne "") 0 47 47
Condition33%1/3
exists $attr->{"onupdate"} and $attr->{"onupdate"} ne ""
!ll&&!rl&&r
4700
MC/DC0%0/2
exists $attr->{"onupdate"} and $attr->{"onupdate"} ne ""
exists $attr->{"onupdate"} $attr->{"onupdate"} ne ""
Truth table33%1/3
A and B
A= exists $attr->{"onupdate"}B= $attr->{"onupdate"} ne ""
ABresult
0X0
100
111
286 my $field_default_val
287 0 = default_field_tbl_val($attr->{type}->{name}, $attr->{onupdate});
288 0 $data .= "ON UPDATE $field_default_val ";
289 }
290  
291 47 ▶ if (exists $attr->{is_null}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{'is_null'}) { } 17 30 47
292 17 ▶ $data .= 'NOT NULL ' unless $attr->{is_null};
Branch: 1 branch
BranchTrueFalseTotal
unless $attr->{"is_null"} 17 0 17
293 17 ▶ $data .= 'NULL ' if $attr->{is_null} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->{"is_null"} == 1 0 17 17
294 }
295 else {
296 30 $data .= 'NOT NULL ';
297 }
298  
299 47 ▶ if (exists $attr->{is_primarykey} and $attr->{is_primarykey} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{"is_primarykey"} and $attr->{"is_primarykey"} == 1) 10 37 47
Condition66%2/3
exists $attr->{"is_primarykey"} and $attr->{"is_primarykey"} == 1
!ll&&!rl&&r
37010
MC/DC50%1/2
exists $attr->{"is_primarykey"} and $attr->{"is_primarykey"} == 1
exists $attr->{"is_primarykey"} $attr->{"is_primarykey"} == 1
Truth table66%2/3
A and B
A= exists $attr->{"is_primarykey"}B= $attr->{"is_primarykey"} == 1
ABresult
0X0
100
111
300 10 $data .= 'PRIMARY KEY ';
301 }
302  
303 47 ▶ if (exists $attr->{is_autoincre} and $attr->{is_autoincre} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{"is_autoincre"} and $attr->{"is_autoincre"} == 1) 9 38 47
Condition66%2/3
exists $attr->{"is_autoincre"} and $attr->{"is_autoincre"} == 1
!ll&&!rl&&r
3809
MC/DC50%1/2
exists $attr->{"is_autoincre"} and $attr->{"is_autoincre"} == 1
exists $attr->{"is_autoincre"} $attr->{"is_autoincre"} == 1
Truth table66%2/3
A and B
A= exists $attr->{"is_autoincre"}B= $attr->{"is_autoincre"} == 1
ABresult
0X0
100
111
304 9 ▶ if ($db_type eq 'sqlite') {
Branch: 1 branch
BranchTrueFalseTotal
if ($db_type eq 'sqlite') { } 6 3 9
305 6 $data .= 'AUTOINCREMENT ';
306 }
307 else {
308 3 $data .= 'AUTO_INCREMENT ';
309 }
310 }
311 }
312 47 $data = trim($data);
313 47 $data = "\t$data";
314 47 return $data;
315 }
316  
317 # For create query table :
318 # ------------------------------------------------------------------------
319 10 ▶sub create_query_table {
Subroutine create_query_table: called CC=20 SCAR=32.0
Pod undocumented
320 10 my $self = shift;
321 10 my $arg_len = scalar @_;
322 10 my ($table_name, $col_list, $col_attr, $table_attr, $db_type);
323 10 my $data = '';
324 10 my $size_tblAttr = 0;
325 10 $db_type = $self->db_type;
326  
327 10 ▶ if ($arg_len == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_len == 3) 5 5 10
328 5 ($table_name, $col_list, $col_attr) = @_;
329 }
330  
331 10 ▶ if ($arg_len == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_len == 4) 5 5 10
332 5 ($table_name, $col_list, $col_attr, $table_attr) = @_;
333 5 ▶ if (ref($table_attr) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $table_attr eq 'HASH') { } 5 0 5
334 5 $size_tblAttr = scalar keys %{$table_attr};
335 }
336 else {
337 0 $table_attr = {};
338 }
339 }
340  
341 10 ▶ if ($arg_len >= 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_len >= 5) 0 10 10
342 0 ($table_name, $col_list, $col_attr, $table_attr, $self->db_type) = @_;
343 0 $size_tblAttr = scalar keys %{$table_attr};
344 }
345  
346 10 $col_attr = $self->table_col_attr_val($col_list, $col_attr);
347 10 $table_attr = $self->table_attr_val($col_attr, $table_attr);
348  
349 10 my $size_col = scalar @{$col_list};
350 10 my $i = 0;
351 10 my @list_col = ();
352 10 ▶ while ($i < $size_col) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $size_col) 47 10 57
353 push @list_col,
354 47 $self->create_colAttr($col_list->[$i], $col_attr->{$col_list->[$i]},
355 $self->db_type);
356 47 $i++;
357 }
358 10 my $list_column = join ",\n", @list_col;
359 10 my $fk_table = '';
360 10 my $index_table = '';
361 10 my $attr_table = '';
362  
363 10 $data .= "CREATE TABLE IF NOT EXISTS $table_name(\n";
364  
365 10 ▶ if ($size_tblAttr != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size_tblAttr != 0) { } 5 5 10
366 5 $data .= "$list_column";
367 5 my $size_fk = 0;
368 5 ▶ if (exists $table_attr->{fk}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $table_attr->{"fk"}) 4 1 5
369 4 $size_fk = 1;
370 4 $fk_table = $table_attr->{fk};
371 4 $data .= ",\n$fk_table";
372 }
373 5 ▶ if (exists $table_attr->{index}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $table_attr->{"index"}) 0 5 5
374 0 $index_table = $table_attr->{index};
375 0 $data .= ",\n$index_table";
376 }
377 5 ▶ if (exists $table_attr->{attr} and $table_attr->{attr} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $table_attr->{'attr'} and $table_attr->{'attr'} ne '') { } 5 0 5
Condition33%1/3
exists $table_attr->{"attr"} and $table_attr->{"attr"} ne ""
!ll&&!rl&&r
005
MC/DC0%0/2
exists $table_attr->{"attr"} and $table_attr->{"attr"} ne ""
exists $table_attr->{"attr"} $table_attr->{"attr"} ne ""
Truth table33%1/3
A and B
A= exists $table_attr->{"attr"}B= $table_attr->{"attr"} ne ""
ABresult
0X0
100
111
378 5 ▶ if ($size_fk == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size_fk == 1) { } 4 1 5
379 4 $attr_table = $table_attr->{attr};
380 4 ▶ $data .= $db_type eq 'sqlite'
Branch: 1 branch
BranchTrueFalseTotal
$db_type eq 'sqlite' || $db_type eq 'pg' ? : 3 1 4
Condition100%3/3
$db_type eq "sqlite" or $db_type eq "pg"
l!l&&r!l&&!r
211
MC/DC100%2/2
$db_type eq "sqlite" or $db_type eq "pg"
$db_type eq "sqlite" $db_type eq "pg"
Truth table100%3/3
A or B
A= $db_type eq "sqlite"B= $db_type eq "pg"
ABresult
1X1
011
000
381 || $db_type eq 'pg' ? " \n)" : ") $attr_table";
382 }
383 else {
384 1 ▶ $data .= $db_type eq 'sqlite'
Branch: 1 branch
BranchTrueFalseTotal
$db_type eq 'sqlite' || $db_type eq 'pg' ? : 1 0 1
Condition33%1/3
$db_type eq "sqlite" or $db_type eq "pg"
l!l&&r!l&&!r
100
MC/DC0%0/2
$db_type eq "sqlite" or $db_type eq "pg"
$db_type eq "sqlite" $db_type eq "pg"
Truth table33%1/3
A or B
A= $db_type eq "sqlite"B= $db_type eq "pg"
ABresult
1X1
011
000
385 || $db_type eq 'pg' ? " \n)" : ") ENGINE=InnoDB DEFAULT CHARSET=utf8";
386 }
387 }
388 else {
389 0 ▶ $data .= $db_type eq 'sqlite'
Branch: 1 branch
BranchTrueFalseTotal
$db_type eq 'sqlite' || $db_type eq 'pg' ? : 0 0 0
Condition0%0/3
$db_type eq "sqlite" or $db_type eq "pg"
l!l&&r!l&&!r
000
MC/DC0%0/2
$db_type eq "sqlite" or $db_type eq "pg"
$db_type eq "sqlite" $db_type eq "pg"
Truth table0%0/3
A or B
A= $db_type eq "sqlite"B= $db_type eq "pg"
ABresult
1X1
011
000
390 || $db_type eq 'pg' ? " \n)" : ") ENGINE=InnoDB DEFAULT CHARSET=utf8";
391 }
392  
393 }
394 else {
395 5 $data .= "$list_column\n";
396 5 ▶ $data .= $db_type eq 'sqlite'
Branch: 1 branch
BranchTrueFalseTotal
$db_type eq 'sqlite' || $db_type eq 'pg' ? : 4 1 5
Condition100%3/3
$db_type eq "sqlite" or $db_type eq "pg"
l!l&&r!l&&!r
311
MC/DC100%2/2
$db_type eq "sqlite" or $db_type eq "pg"
$db_type eq "sqlite" $db_type eq "pg"
Truth table100%3/3
A or B
A= $db_type eq "sqlite"B= $db_type eq "pg"
ABresult
1X1
011
000
397 || $db_type eq 'pg' ? ")" : ") ENGINE=InnoDB DEFAULT CHARSET=utf8";
398 }
399 10 return $data;
400 }
401  
402 #######################################################################################
403 # FOR Helper
404 #######################################################################################
405  
406 # For check engine :
407 # ------------------------------------------------------------------------
408 3 ▶sub _check_engine {
Subroutine _check_engine: called CC=2 SCAR=7.2
409 3 my ($self, $engine) = @_;
410  
411 3 $engine = lc $engine;
412 3 my %list_engine = ('myisam' => 'MyISAM', 'innodb' => 'InnoDB',);
413  
414 3 ▶ if (exists $list_engine{$engine}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $list_engine{$engine}) { } 3 0 3
415 3 return $list_engine{$engine};
416 }
417 else {
418 0 return $list_engine{'innodb'};
419 }
420 }
421  
422 17 1;
« blib/lib/CellBIS/SQL/Abstract/Test.pm ↑ Summary lib/CellBIS/SQL/Abstract/Util.pm »