lib/SQL/Admin/Driver/DB2/Producer.pm

filter: Statementstmt 85.1% 69 / 81 Branchbran 70.0% 7 / 10 Conditioncond 53.3% 8 / 15 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 84.2% 32 / 38 Podpod 0.0% 0 / 33 totaltotal 63.9% 117 / 183 CC 11 SCAR 9.5
CC
11
Cov
79%
_escape_identifier
8.8
select_what
6.0
alter_table
2.1
CRAP 2.6
« lib/SQL/Admin/Utils.pm ↑ Summary lib/SQL/Admin/Catalog/Sequence.pm »
1  
2 package SQL::Admin::Driver::DB2::Producer;
3 2 ▶use base qw( SQL::Admin::Driver::Base::Producer );
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = v0.5.0;
9  
10 ######################################################################
11  
12 2 ▶use SQL::Admin::Driver::DB2::Keywords qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 our %DATA_TYPE_MAP = (
15 'int2' => 'smallint',
16 'int4' => 'integer',
17 'int8' => 'bigint',
18  
19 'text' => 'varchar',
20 );
21  
22 ######################################################################
23  
24 2 our $ESCAPE_ALL_IDENTIFIERS = 0;
25 2 our $ESCAPE_NONRESERVED_KEYWORDS = 0;
26 2 our $ESCAPE_SQL_KEYWORDS = 0;
27  
28 ######################################################################
29  
30 2 our %REFERENTIAL_ACTION = (
31 cascade => [ 'CASCADE' ],
32 no_action => [ 'NO', 'ACTION' ],
33 restrict => [ 'RESTRICT' ],
34 set_null => [ 'SET', 'NULL' ],
35 );
36  
37 ######################################################################
38 ######################################################################
39  
40 124 ▶sub _escape_identifier { # ;
Subroutine _escape_identifier: called CC=7 SCAR=21.8
41 124 my ($self, $identifier) = @_;
42 124 my $lc = lc $identifier;
43  
44 $identifier = '"' . $identifier . '"'
45 if $ESCAPE_ALL_IDENTIFIERS
46 || $RESERVED_KEYWORDS{ $lc }
47 || ($ESCAPE_NONRESERVED_KEYWORDS && $NONRESERVED_KEYWORDS{ $lc })
48 124 ▶ || ($ESCAPE_SQL_KEYWORDS && $SQL_KEYWORDS{ $lc })
Branch: 1 branch
BranchTrueFalseTotal
if $SQL::Admin::Driver::DB2::Producer::ESCAPE_ALL_IDENTIFIERS or $SQL::Admin::Driver::DB2::Producer::RESERVED_KEYWORDS{$lc} or $SQL::Admin::Driver::DB2::Producer::ESCAPE_NONRESERVED_KEYWORDS and $SQL::Admin::Driver::DB2::Producer::NONRESERVED_KEYWORDS{$lc} or $SQL::Admin::Driver::DB2::Producer::ESCAPE_SQL_KEYWORDS and $SQL::Admin::Driver::DB2::Producer::SQL_KEYWORDS{$lc} 9 115 124
Condition53%8/15
$SQL::Admin::Driver::DB2::Producer::ESCAPE_ALL_IDENTIFIERS or $SQL::Admin::Driver::DB2::Producer::RESERVED_KEYWORDS{$lc} or $SQL::Admin::Driver::DB2::Producer::ESCAPE_NONRESERVED_KEYWORDS and $SQL::Admin::Driver::DB2::Producer::NONRESERVED_KEYWORDS{$lc} or $SQL::Admin::Driver::DB2::Producer::ESCAPE_SQL_KEYWORDS and $SQL::Admin::Driver::DB2::Producer::SQL_KEYWORDS{$lc}
l!l&&r!l&&!r
90115
$SQL::Admin::Driver::DB2::Producer::ESCAPE_ALL_IDENTIFIERS or $SQL::Admin::Driver::DB2::Producer::RESERVED_KEYWORDS{$lc} or $SQL::Admin::Driver::DB2::Producer::ESCAPE_NONRESERVED_KEYWORDS and $SQL::Admin::Driver::DB2::Producer::NONRESERVED_KEYWORDS{$lc}
l!l&&r!l&&!r
90115
$SQL::Admin::Driver::DB2::Producer::ESCAPE_ALL_IDENTIFIERS or $SQL::Admin::Driver::DB2::Producer::RESERVED_KEYWORDS{$lc}
l!l&&r!l&&!r
09115
$SQL::Admin::Driver::DB2::Producer::ESCAPE_NONRESERVED_KEYWORDS and $SQL::Admin::Driver::DB2::Producer::NONRESERVED_KEYWORDS{$lc}
!ll&&!rl&&r
11500
$SQL::Admin::Driver::DB2::Producer::ESCAPE_SQL_KEYWORDS and $SQL::Admin::Driver::DB2::Producer::SQL_KEYWORDS{$lc}
!ll&&!rl&&r
11500
MC/DC16%1/6
$SQL::Admin::Driver::DB2::Producer::ESCAPE_ALL_IDENTIFIERS or $SQL::Admin::Driver::DB2::Producer::RESERVED_KEYWORDS{$lc} or $SQL::Admin::Driver::DB2::Producer::ESCAPE_NONRESERVED_KEYWORDS and $SQL::Admin::Driver::DB2::Producer::NONRESERVED_KEYWORDS{$lc} or $SQL::Admin::Driver::DB2::Producer::ESCAPE_SQL_KEYWORDS and $SQL::Admin::Driver::DB2::Producer::SQL_KEYWORDS{$lc}
$SQL::Admin::Driver::DB2::Producer::ESCAPE_ALL_IDENTIFIERS $SQL::Admin::Driver::DB2::Producer::RESERVED_KEYWORDS{$lc} $SQL::Admin::Driver::DB2::Producer::ESCAPE_NONRESERVED_KEYWORDS $SQL::Admin::Driver::DB2::Producer::NONRESERVED_KEYWORDS{$lc} $SQL::Admin::Driver::DB2::Producer::ESCAPE_SQL_KEYWORDS $SQL::Admin::Driver::DB2::Producer::SQL_KEYWORDS{$lc}
Truth table22%2/9
A or B or C and D or E and F
A= $SQL::Admin::Driver::DB2::Producer::ESCAPE_ALL_IDENTIFIERSB= $SQL::Admin::Driver::DB2::Producer::RESERVED_KEYWORDS{$lc}C= $SQL::Admin::Driver::DB2::Producer::ESCAPE_NONRESERVED_KEYWORDSD= $SQL::Admin::Driver::DB2::Producer::NONRESERVED_KEYWORDS{$lc}E= $SQL::Admin::Driver::DB2::Producer::ESCAPE_SQL_KEYWORDSF= $SQL::Admin::Driver::DB2::Producer::SQL_KEYWORDS{$lc}
ABCDEFresult
1XXXXX1
01XXXX1
0011XX1
000X111
0010111
000X0X0
000X100
00100X0
0010100
49 ;
50  
51 ##################################################################
52  
53 124 $identifier;
54 }
55  
56  
57 ######################################################################
58 ######################################################################
59 26 ▶sub data_type { # ;
Subroutine data_type: called CC=2 SCAR=6.9
Pod undocumented
60 26 my ($self, $data, $parent) = @_;
61  
62 $data = $DATA_TYPE_MAP{lc $data}
63 26 ▶ if exists $DATA_TYPE_MAP{lc $data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $SQL::Admin::Driver::DB2::Producer::DATA_TYPE_MAP{lc $data} 18 8 26
64  
65 26 $self->SUPER::data_type ($data, $parent);
66 }
67  
68  
69 ######################################################################
70 ######################################################################
71 4 ▶sub current_timestamp { # ;
Subroutine current_timestamp: called CC=1 SCAR=0.0
Pod undocumented
72 4 'CURRENT', 'TIMESTAMP';
73 }
74  
75  
76 ######################################################################
77 ######################################################################
78 1 ▶sub current_time { # ;
Subroutine current_time: called CC=1 SCAR=0.0
Pod undocumented
79 1 'CURRENT', 'TIME';
80 }
81  
82  
83 ######################################################################
84 ######################################################################
85 1 ▶sub current_date { # ;
Subroutine current_date: called CC=1 SCAR=0.0
Pod undocumented
86 1 'CURRENT', 'DATE';
87 }
88  
89  
90 ######################################################################
91 ######################################################################
92 9 ▶sub default_clause { # ;
Subroutine default_clause: called CC=1 SCAR=0.0
Pod undocumented
93 9 my ($self, $def) = @_;
94  
95 9 'WITH', 'DEFAULT', $self->__apply (%$def);
96 }
97  
98  
99 ######################################################################
100 ######################################################################
101  
102 0 ▶sub db2_in_tablespace { # ;
Subroutine db2_in_tablespace: not called CC=1 SCAR=6.9
Pod undocumented
103 0 'IN', '"' . $_[1] . '"';
104 }
105  
106  
107 ######################################################################
108 ######################################################################
109 0 ▶sub db2_data_capture { # ;
Subroutine db2_data_capture: not called CC=1 SCAR=6.9
Pod undocumented
110 0 'DATA', 'CAPTURE', $_[1];
111 }
112  
113  
114 ######################################################################
115 ######################################################################
116 0 ▶sub db2_pctfree { # ;
Subroutine db2_pctfree: not called CC=1 SCAR=6.9
Pod undocumented
117 0 'PCTFREE', $_[1];
118 }
119  
120  
121 ######################################################################
122 ######################################################################
123 2 ▶sub db2_locksize { # ;
Subroutine db2_locksize: called CC=1 SCAR=0.0
Pod undocumented
124 }
125  
126  
127 ######################################################################
128 ######################################################################
129 2 ▶sub db2_append { # ;
Subroutine db2_append: called CC=1 SCAR=0.0
Pod undocumented
130 }
131  
132  
133 ######################################################################
134 ######################################################################
135 2 ▶sub db2_volatile { # ;
Subroutine db2_volatile: called CC=1 SCAR=0.0
Pod undocumented
136 }
137  
138  
139 ######################################################################
140 ######################################################################
141 2 ▶sub db2_log_index { # ;
Subroutine db2_log_index: called CC=1 SCAR=0.0
Pod undocumented
142 }
143  
144  
145 ######################################################################
146 ######################################################################
147 1 ▶sub db2_enforced { # ;
Subroutine db2_enforced: called CC=1 SCAR=0.0
Pod undocumented
148 # $_ ? () : ('NOT'), 'ENFORCED';
149 }
150  
151  
152 ######################################################################
153 ######################################################################
154 1 ▶sub db2_optimize { # ;
Subroutine db2_optimize: called CC=1 SCAR=0.0
Pod undocumented
155 # $_ ? 'ENABLED' : 'DISABLED', 'QUERY', 'OPTIMIZATION';
156 }
157  
158  
159 ######################################################################
160 ######################################################################
161 8 ▶sub autoincrement { # ;
Subroutine autoincrement: called CC=2 SCAR=6.9
Pod undocumented
162 8 my ($self, $def) = @_;
163 8 my $options = do { local $, = ', '; $self->__apply (sequence_options => $def) };
164  
165 8 ▶ $options = '(' . $options . ')'
Branch: 1 branch
BranchTrueFalseTotal
if $options 6 2 8
166 if $options;
167  
168 8 'GENERATED', 'AS', 'IDENTITY', $options;
169 }
170  
171  
172 ######################################################################
173 ######################################################################
174  
175 6 ▶sub sequence_type { # ;
Subroutine sequence_type: called CC=1 SCAR=0.0
Pod undocumented
176 6 my ($self, $def) = @_;
177  
178 6 'AS', $self->data_type ($def);
179 }
180  
181  
182 ######################################################################
183 ######################################################################
184 13 ▶sub sequence_options { # ;
Subroutine sequence_options: called CC=1 SCAR=0.0
Pod undocumented
185 13 my ($self, $def) = @_;
186  
187 13 map $self->__call ($_, $def), (
188 'sequence_start_with',
189 'sequence_increment_by',
190 'sequence_minvalue',
191 'sequence_maxvalue',
192 'sequence_cache',
193 );
194 }
195  
196  
197 ######################################################################
198 ######################################################################
199 10 ▶sub sequence_start_with { # ;
Subroutine sequence_start_with: called CC=1 SCAR=0.0
Pod undocumented
200 10 map +('START', 'WITH', $_), grep $_ != 1, $_[1];
201 }
202  
203  
204 ######################################################################
205 ######################################################################
206 5 ▶sub sequence_increment_by { # ;
Subroutine sequence_increment_by: called CC=1 SCAR=0.0
Pod undocumented
207 5 map +('INCREMENT', 'BY', $_), grep $_ != 1, $_[1];
208 }
209  
210  
211 ######################################################################
212 ######################################################################
213 3 ▶sub sequence_minvalue { # ;
Subroutine sequence_minvalue: called CC=1 SCAR=0.0
Pod undocumented
214 3 my ($self, $def) = @_;
215  
216 3 map +('MINVALUE', $_), grep defined, $def;
217 }
218  
219  
220 ######################################################################
221 ######################################################################
222 3 ▶sub sequence_maxvalue { # ;
Subroutine sequence_maxvalue: called CC=1 SCAR=0.0
Pod undocumented
223 3 my ($self, $def) = @_;
224  
225 3 map +('MAXVALUE', $_), grep defined, $def;
226 }
227  
228  
229 ######################################################################
230 ######################################################################
231 2 ▶sub sequence_cache { # ;
Subroutine sequence_cache: called CC=1 SCAR=0.0
Pod undocumented
232 2 my ($self, $def) = @_;
233  
234 2 map +('CACHE', $_), grep $_ != 20, grep defined, $def;
235 }
236  
237  
238 ######################################################################
239 ######################################################################
240  
241 0 ▶sub alter_table_actions { # ;
Subroutine alter_table_actions: not called CC=1 SCAR=6.9
Pod undocumented
242 0 my ($self, $def) = @_;
243  
244 0 map $self->__apply (alter_table_action => $_), @$def;
245 }
246  
247  
248 ######################################################################
249 ######################################################################
250 8 ▶sub alter_table_action { # ;
Subroutine alter_table_action: called CC=1 SCAR=0.0
Pod undocumented
251 8 my ($self, $def) = @_;
252  
253 8 $self->__apply (%$def);
254 }
255  
256  
257 ######################################################################
258 ######################################################################
259 1 ▶sub delete_rule { # ;
Subroutine delete_rule: called CC=1 SCAR=0.0
Pod undocumented
260 1 my ($self, $def) = @_;
261  
262 1 map +('ON', 'DELETE', @{ $REFERENTIAL_ACTION{$_} }), grep defined, $def;
263 }
264  
265  
266 ######################################################################
267 ######################################################################
268 1 ▶sub update_rule { # ;
Subroutine update_rule: called CC=1 SCAR=0.0
Pod undocumented
269 1 my ($self, $def) = @_;
270  
271 1 map +('ON', 'UPDATE', @{ $REFERENTIAL_ACTION{$_} }), grep defined, $def;
272 }
273  
274  
275 ######################################################################
276 ######################################################################
277 1 ▶sub foreign_key_constraint { # ;
Subroutine foreign_key_constraint: called CC=1 SCAR=0.0
Pod undocumented
278 1 my ($self, $def) = @_;
279  
280 (
281 1 $self->SUPER::foreign_key_constraint ($def),
282 $self->__call (db2_enforced => $def),
283 $self->__call (db2_optimize => $def),
284 );
285 }
286  
287  
288 ######################################################################
289 ######################################################################
290  
291 7 ▶sub create_sequence { # ;
Subroutine create_sequence: called CC=1 SCAR=0.0
Pod undocumented
292 7 my ($self, $def) = @_;
293  
294 (
295 7 'CREATE',
296 'SEQUENCE',
297 $self->__call (sequence_name => $def),
298 $self->__call (sequence_type => $def),
299 $self->__call (sequence_options => $def),
300 );
301 }
302  
303  
304 ######################################################################
305 ######################################################################
306 3 ▶sub create_index { # ;
Subroutine create_index: called CC=1 SCAR=0.0
Pod undocumented
307 3 my ($self, $def) = @_;
308 3 join ' ', (
309 'CREATE',
310 $self->__call (index_unique => $def),
311 'INDEX',
312 $self->__call (index_name => $def),
313 'ON',
314 $self->__call (table_name => $def),
315 $self->__call (index_column_list => $def),
316 $self->__call (index_options => $def),
317 );
318 }
319  
320  
321 ######################################################################
322 ######################################################################
323 1 ▶sub create_table { # ;
Subroutine create_table: called CC=1 SCAR=0.0
Pod undocumented
324 1 my ($self, $def) = @_;
325  
326 1 join ' ', (
327 'CREATE',
328 'TABLE',
329 $self->__call (table_name => $def),
330 $self->__call (table_content => $def),
331 $self->__call (table_options => $def),
332 );
333 }
334  
335  
336 ######################################################################
337 ######################################################################
338 1 ▶sub alter_table { # ;
Subroutine alter_table: called CC=2 SCAR=7.4
Pod undocumented
339 1 my ($self, $def) = @_;
340  
341 1 my @list = map $self->__apply (%$_), @{ $def->{alter_table_actions} };
342  
343 1 ▶ return unless @list;
Branch: 1 branch
BranchTrueFalseTotal
unless @list 1 0 1
344  
345 (
346 0 'ALTER',
347 'TABLE',
348 $self->__call (table_name => $def),
349 @list
350 );
351 }
352  
353  
354 ######################################################################
355 ######################################################################
356  
357 0 ▶sub create_schema { # ;
Subroutine create_schema: not called CC=1 SCAR=6.9
Pod undocumented
358 0 my ($self, $def) = @_;
359  
360 (
361 'CREATE',
362 'SCHEMA',
363 0 $self->_escape_identifier ($def->{schema_identifier}),
364 );
365 }
366  
367  
368 ######################################################################
369 ######################################################################
370  
371 0 ▶sub select_what { # ;
Subroutine select_what: not called CC=2 SCAR=17.9
Pod undocumented
372 0 my ($self, $def, $parent) = @_;
373 0 my ($key, @res) = $self->SUPER::select_what ($def, $parent);
374  
375 ($key, @res) = ('VALUES', '(', @res, ')')
376 0 ▶ unless exists $parent->{select_from};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $parent->{"select_from"} 0 0 0
377  
378 0 ($key, @res);
379 }
380  
381  
382 ######################################################################
383 ######################################################################
384  
385 package SQL::Admin::Driver::DB2::Producer;
386  
387 2 1;
« lib/SQL/Admin/Utils.pm ↑ Summary lib/SQL/Admin/Catalog/Sequence.pm »