blib/lib/SQL/Translator/Producer/Oracle.pm

filter: Statementstmt 86.3% 265 / 307 Branchbran 66.5% 137 / 206 Conditioncond 53.9% 48 / 89 MC/DCmcdc 28.8% 15 / 52 Subroutinesub 100% 13 / 13 Podpod 75.0% 6 / 8 totaltotal 71.7% 484 / 675 SCAR 62.3
CC
149
Cov
75%
create_table
338.0
create_field
62.9
mk_name
20.0
CRAP 506.4
« blib/lib/SQL/Translator/Parser/DBI/SQLServer.pm ↑ Summary blib/lib/SQL/Translator/Parser/DBI/Sybase.pm »
1 package SQL::Translator::Producer::Oracle;
2  
3 =head1 NAME
4  
5 SQL::Translator::Producer::Oracle - Oracle SQL producer
6  
7 =head1 SYNOPSIS
8  
9 use SQL::Translator;
10  
11 my $t = SQL::Translator->new( parser => '...', producer => 'Oracle' );
12 print $translator->translate( $file );
13  
14 =head1 DESCRIPTION
15  
16 Creates an SQL DDL suitable for Oracle.
17  
18 =head1 producer_args
19  
20 =over
21  
22 =item delay_constraints
23  
24 This option remove the primary key and other key constraints from the
25 CREATE TABLE statement and adds ALTER TABLEs at the end with it.
26  
27 =item quote_field_names
28  
29 Controls whether quotes are being used around column names in generated DDL.
30  
31 =item quote_table_names
32  
33 Controls whether quotes are being used around table, sequence and trigger names in
34 generated DDL.
35  
36 =back
37  
38 =head1 NOTES
39  
40 =head2 Autoincremental primary keys
41  
42 This producer uses sequences and triggers to autoincrement primary key
43 columns, if necessary. SQLPlus and DBI expect a slightly different syntax
44 of CREATE TRIGGER statement. You might have noticed that this
45 producer returns a scalar containing all statements concatenated by
46 newlines or an array of single statements depending on the context
47 (scalar, array) it has been called in.
48  
49 SQLPlus expects following trigger syntax:
50  
51 CREATE OR REPLACE TRIGGER ai_person_id
52 BEFORE INSERT ON person
53 FOR EACH ROW WHEN (
54 new.id IS NULL OR new.id = 0
55 )
56 BEGIN
57 SELECT sq_person_id.nextval
58 INTO :new.id
59 FROM dual;
60 END;
61 /
62  
63 Whereas if you want to create the same trigger using L<DBI/do>, you need
64 to omit the last slash:
65  
66 my $dbh = DBI->connect('dbi:Oracle:mysid', 'scott', 'tiger');
67 $dbh->do("
68 CREATE OR REPLACE TRIGGER ai_person_id
69 BEFORE INSERT ON person
70 FOR EACH ROW WHEN (
71 new.id IS NULL OR new.id = 0
72 )
73 BEGIN
74 SELECT sq_person_id.nextval
75 INTO :new.id
76 FROM dual;
77 END;
78 ");
79  
80 If you call this producer in array context, we expect you want to process
81 the returned array of statements using L<DBI> like
82 L<DBIx::Class::Schema/deploy> does.
83  
84 To get this working we removed the slash in those statements in version
85 0.09002 of L<SQL::Translator> when called in array context. In scalar
86 context the slash will be still there to ensure compatibility with SQLPlus.
87  
88 =cut
89  
90 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 10 our ( $DEBUG, $WARN );
93 10 our $VERSION = '1.6_3';
94 10 ▶$DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $SQL::Translator::Producer::Oracle::DEBUG 10 0 10
95  
96 10 ▶use base 'SQL::Translator::Producer';
Subroutine BEGIN: called CC=1 SCAR=0.0
97 10 ▶use SQL::Translator::Schema::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 10 ▶use SQL::Translator::Utils qw(header_comment);
Subroutine BEGIN: called CC=1 SCAR=0.0
99  
100 10 my %translate = (
101 #
102 # MySQL types
103 #
104 bigint => 'number',
105 double => 'float',
106 decimal => 'number',
107 float => 'float',
108 int => 'number',
109 integer => 'number',
110 mediumint => 'number',
111 smallint => 'number',
112 tinyint => 'number',
113 char => 'char',
114 varchar => 'varchar2',
115 tinyblob => 'blob',
116 blob => 'blob',
117 mediumblob => 'blob',
118 longblob => 'blob',
119 tinytext => 'varchar2',
120 text => 'clob',
121 longtext => 'clob',
122 mediumtext => 'clob',
123 enum => 'varchar2',
124 set => 'varchar2',
125 date => 'date',
126 datetime => 'date',
127 time => 'date',
128 timestamp => 'date',
129 year => 'date',
130  
131 #
132 # PostgreSQL types
133 #
134 numeric => 'number',
135 'double precision' => 'number',
136 serial => 'number',
137 bigserial => 'number',
138 money => 'number',
139 character => 'char',
140 'character varying' => 'varchar2',
141 bytea => 'BLOB',
142 interval => 'number',
143 boolean => 'number',
144 point => 'number',
145 line => 'number',
146 lseg => 'number',
147 box => 'number',
148 path => 'number',
149 polygon => 'number',
150 circle => 'number',
151 cidr => 'number',
152 inet => 'varchar2',
153 macaddr => 'varchar2',
154 bit => 'number',
155 'bit varying' => 'number',
156  
157 #
158 # Oracle types
159 #
160 number => 'number',
161 varchar2 => 'varchar2',
162 long => 'clob',
163 );
164  
165 #
166 # Oracle 8/9 max size of data types from:
167 # http://www.ss64.com/orasyntax/datatypes.html
168 #
169 10 my %max_size = (
170 char => 2000,
171 float => 126,
172 nchar => 2000,
173 nvarchar2 => 4000,
174 number => [ 38, 127 ],
175 raw => 2000,
176 varchar => 4000, # only synonym for varchar2
177 varchar2 => 4000,
178 );
179  
180 10 my $max_id_length = 30;
181 10 my %used_identifiers = ();
182 10 my %global_names;
183 my %truncated;
184  
185 # Quote used to escape table, field, sequence and trigger names
186 10 my $quote_char = '"';
187  
188 sub produce {
189 10 ▶ my $translator = shift;
Subroutine produce: called CC=13 SCAR=25.7
Pod documented
190 10 $DEBUG = $translator->debug;
191 10 ▶ $WARN = $translator->show_warnings || 0;
Condition50%1/2
$translator->show_warnings || 0
l!l
010
MC/DC0%0/1
$translator->show_warnings || 0
$translator->show_warnings
Truth table50%1/2
A
A= $translator->show_warnings
Aresult
11
00
192 10 my $no_comments = $translator->no_comments;
193 10 my $add_drop_table = $translator->add_drop_table;
194 10 my $schema = $translator->schema;
195 10 ▶ my $oracle_version = $translator->producer_args->{oracle_version} || 0;
Condition50%1/2
$translator->producer_args->{'oracle_version'} || 0
l!l
010
MC/DC0%0/1
$translator->producer_args->{'oracle_version'} || 0
$translator->producer_args->{'oracle_version'}
Truth table50%1/2
A
A= $translator->producer_args->{'oracle_version'}
Aresult
11
00
196 10 my $delay_constraints = $translator->producer_args->{delay_constraints};
197 10 my ($output, $create, @table_defs, @fk_defs, @trigger_defs, @index_defs, @constraint_defs);
198  
199 10 ▶ $create .= header_comment unless ($no_comments);
Branch: 1 branch
BranchTrueFalseTotal
unless $no_comments 4 6 10
200 10 ▶ my $qt = 1 if $translator->quote_table_names;
Branch: 1 branch
BranchTrueFalseTotal
if $translator->quote_table_names 6 4 10
201 10 ▶ my $qf = 1 if $translator->quote_field_names;
Branch: 1 branch
BranchTrueFalseTotal
if $translator->quote_field_names 6 4 10
202  
203 10 ▶ if ( $translator->parser_type =~ /mysql/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($translator->parser_type =~ /mysql/i) 1 9 10
204 1 ▶ $create .=
Branch: 1 branch
BranchTrueFalseTotal
unless $no_comments 1 0 1
205 "-- We assume that default NLS_DATE_FORMAT has been changed\n".
206 "-- but we set it here anyway to be self-consistent.\n"
207 unless $no_comments;
208  
209 1 $create .=
210 "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';\n\n";
211 }
212  
213 10 for my $table ( $schema->get_tables ) {
214 20 my ( $table_def, $fk_def, $trigger_def, $index_def, $constraint_def ) = create_table(
215 $table,
216 {
217 add_drop_table => $add_drop_table,
218 show_warnings => $WARN,
219 no_comments => $no_comments,
220 delay_constraints => $delay_constraints,
221 quote_table_names => $qt,
222 quote_field_names => $qf,
223 }
224 );
225 20 push @table_defs, @$table_def;
226 20 push @fk_defs, @$fk_def;
227 20 push @trigger_defs, @$trigger_def;
228 20 push @index_defs, @$index_def;
229 20 push @constraint_defs, @$constraint_def;
230 }
231  
232 10 my (@view_defs);
233 10 foreach my $view ( $schema->get_views ) {
234 5 my ( $view_def ) = create_view(
235 $view,
236 {
237 add_drop_view => $add_drop_table,
238 quote_table_names => $qt,
239 }
240 );
241 5 push @view_defs, @$view_def;
242 }
243  
244 10 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 2 8 10
245 2 ▶ return defined $create ? $create : (), @table_defs, @view_defs, @fk_defs, @trigger_defs, @index_defs, @constraint_defs;
Branch: 1 branch
BranchTrueFalseTotal
defined $create ? : 0 2 2
246 }
247 else {
248 8 $create .= join (";\n\n", @table_defs, @view_defs, @fk_defs, @index_defs, @constraint_defs);
249 8 $create .= ";\n\n";
250 # If wantarray is not set we have to add "/" in this statement
251 # DBI->do() needs them omitted
252 # triggers may NOT end with a semicolon but a "/" instead
253 $create .= "$_/\n\n"
254 8 for @trigger_defs;
255 8 return $create;
256 }
257 }
258  
259 sub create_table {
260 21 ▶ my ($table, $options) = @_;
Subroutine create_table: called CC=70 SCAR=58.2
Pod documented
261 21 my $qt = $options->{quote_table_names};
262 21 my $qf = $options->{quote_field_names};
263 21 my $table_name = $table->name;
264 21 my $table_name_q = quote($table_name,$qt);
265  
266 21 my $item = '';
267 21 my $drop;
268 21 my (@create, @field_defs, @constraint_defs, @fk_defs, @trigger_defs);
269  
270 21 ▶ push @create, "--\n-- Table: $table_name\n--" unless $options->{no_comments};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"no_comments"} 5 16 21
271 21 ▶ push @create, qq[DROP TABLE $table_name_q CASCADE CONSTRAINTS] if $options->{add_drop_table};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"add_drop_table"} 16 5 21
272  
273 21 my ( %field_name_scope, @field_comments );
274 21 for my $field ( $table->get_fields ) {
275 84 my ($field_create, $field_defs, $trigger_defs, $field_comments) =
276 create_field($field, $options, \%field_name_scope);
277 84 ▶ push @create, @$field_create if ref $field_create;
Branch: 1 branch
BranchTrueFalseTotal
if ref $field_create 84 0 84
278 84 ▶ push @field_defs, @$field_defs if ref $field_defs;
Branch: 1 branch
BranchTrueFalseTotal
if ref $field_defs 84 0 84
279 84 ▶ push @trigger_defs, @$trigger_defs if ref $trigger_defs;
Branch: 1 branch
BranchTrueFalseTotal
if ref $trigger_defs 84 0 84
280 84 ▶ push @field_comments, @$field_comments if ref $field_comments;
Branch: 1 branch
BranchTrueFalseTotal
if ref $field_comments 84 0 84
281 }
282  
283 #
284 # Table options
285 #
286 21 my @table_options;
287 21 for my $opt ( $table->options ) {
288 7 ▶ if ( ref $opt eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opt eq "HASH") 5 2 7
289 5 my ( $key, $value ) = each %$opt;
290 5 ▶ if ( ref $value eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 5 5
elsif (not defined $value) { } 0 5 5
291 push @table_options, "$key\n(\n". join ("\n",
292 0 map { " $_->[0]\t$_->[1]" }
293 0 map { [ each %$_ ] }
294 @$value
295 )."\n)";
296 }
297 elsif ( !defined $value ) {
298 0 push @table_options, $key;
299 }
300 else {
301 5 push @table_options, "$key $value";
302 }
303 }
304 }
305  
306 #
307 # Table constraints
308 #
309 21 for my $c ( $table->get_constraints ) {
310 35 ▶ my $name = $c->name || '';
Condition100%2/2
$c->name || ''
l!l
1322
MC/DC100%1/1
$c->name || ''
$c->name
Truth table100%2/2
A
A= $c->name
Aresult
11
00
311 35 my @fields = map { quote($_,$qf) } $c->fields;
312 35 my @rfields = map { quote($_,$qf) } $c->reference_fields;
313  
314 35 ▶ next if !@fields && $c->type ne CHECK_C;
Branch: 1 branch
BranchTrueFalseTotal
if not @fields and $c->type ne "CHECK" 0 35 35
Condition33%1/3
not @fields and $c->type ne "CHECK"
!ll&&!rl&&r
3500
MC/DC0%0/2
not @fields and $c->type ne "CHECK"
not @fields $c->type ne "CHECK"
Truth table33%1/3
not(A) and B
A= not @fieldsB= $c->type ne "CHECK"
ABresult
0X0
100
111
315  
316 35 ▶ if ( $c->type eq PRIMARY_KEY ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($c->type eq 'PRIMARY KEY') { } 18 17 35
elsif ($c->type eq 'UNIQUE') { } 10 7 17
elsif ($c->type eq 'CHECK') { } 0 7 7
elsif ($c->type eq 'FOREIGN KEY') { } 7 0 7
317 # create a name if delay_constraints
318 $name ||= mk_name( $table_name, 'pk' )
319 18 ▶ if $options->{delay_constraints};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"delay_constraints"} 2 16 18
Condition33%1/3
$name ||= mk_name($table_name, "pk")
l!l&&r!l&&!r
020
MC/DC0%0/2
$name ||= mk_name($table_name, "pk")
$name mk_name($table_name, "pk")
Truth table33%1/3
A ||= B
A= $nameB= mk_name($table_name, "pk")
ABresult
1X1
011
000
320 18 $name = quote($name,$qf);
321 18 ▶ push @constraint_defs, ($name ? "CONSTRAINT $name " : '') .
Branch: 1 branch
BranchTrueFalseTotal
$name ? : 2 16 18
322 'PRIMARY KEY (' . join( ', ', @fields ) . ')';
323 }
324 elsif ( $c->type eq UNIQUE ) {
325 # Don't create UNIQUE constraints identical to the primary key
326 10 ▶ if ( my $pk = $table->primary_key ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pk = $table->primary_key) 10 0 10
327 10 my $u_fields = join(":", @fields);
328 10 my $pk_fields = join(":", $pk->fields);
329 10 ▶ next if $u_fields eq $pk_fields;
Branch: 1 branch
BranchTrueFalseTotal
if $u_fields eq $pk_fields 0 10 10
330 }
331  
332 10 ▶ if ($name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) { } 10 0 10
333 # Force prepend of table_name as ORACLE doesn't allow duplicate
334 # CONSTRAINT names even for different tables (ORA-02264)
335 10 ▶ $name = mk_name( "${table_name}_$name", 'u' ) unless $name =~ /^$table_name/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^$table_name/ 10 0 10
336 }
337 else {
338 0 $name = mk_name( $table_name, 'u' );
339 }
340  
341 10 $name = quote($name, $qf);
342  
343 10 for my $f ( $c->fields ) {
344 10 ▶ my $field_def = $table->get_field( $f ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $field_def = $table->get_field($f) or next 0 10 10
345 10 ▶ my $dtype = $translate{ ref $field_def->data_type eq "ARRAY" ? $field_def->data_type->[0] : $field_def->data_type} or next;
Branch: 2 branches
BranchTrueFalseTotal
my $dtype = $translate{ref $field_def->data_type eq "ARRAY" ? $field_def->data_type->[0] : $field_def->data_type} or next 0 10 10
ref $field_def->data_type eq 'ARRAY' ? : 0 10 10
346 10 ▶ if ( $WARN && $dtype =~ /clob/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SQL::Translator::Producer::Oracle::WARN and $dtype =~ /clob/i) 0 10 10
Condition33%1/3
$SQL::Translator::Producer::Oracle::WARN and $dtype =~ /clob/i
!ll&&!rl&&r
1000
MC/DC0%0/2
$SQL::Translator::Producer::Oracle::WARN and $dtype =~ /clob/i
$SQL::Translator::Producer::Oracle::WARN $dtype =~ /clob/i
Truth table33%1/3
A and B
A= $SQL::Translator::Producer::Oracle::WARNB= $dtype =~ /clob/i
ABresult
0X0
100
111
347 0 warn "Oracle will not allow UNIQUE constraints on " .
348 "CLOB field '" . $field_def->table->name . '.' .
349 $field_def->name . ".'\n"
350 }
351 }
352  
353 10 push @constraint_defs, "CONSTRAINT $name UNIQUE " .
354 '(' . join( ', ', @fields ) . ')';
355 }
356 elsif ( $c->type eq CHECK_C ) {
357 0 ▶ $name ||= mk_name( $name || $table_name, 'ck' );
Condition0%0/6
$name ||= mk_name($name || $table_name, "ck")
l!l&&r!l&&!r
000
$name || $table_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$name ||= mk_name($name || $table_name, "ck")
$name mk_name($name || $table_name, "ck")
MC/DC0%0/2
$name || $table_name
$name $table_name
Truth table0%0/3
A ||= B
A= $nameB= mk_name($name || $table_name, "ck")
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $nameB= $table_name
ABresult
1X1
011
000
358 0 $name = quote($name, $qf);
359 0 ▶ my $expression = $c->expression || '';
Condition0%0/2
$c->expression || ''
l!l
00
MC/DC0%0/1
$c->expression || ''
$c->expression
Truth table0%0/2
A
A= $c->expression
Aresult
11
00
360 0 push @constraint_defs, "CONSTRAINT $name CHECK ($expression)";
361 }
362 elsif ( $c->type eq FOREIGN_KEY ) {
363 7 $name = mk_name( join('_', $table_name, $c->fields). '_fk' );
364 7 $name = quote($name, $qf);
365 7 ▶ my $on_delete = uc ($c->on_delete || '');
Condition50%1/2
$c->on_delete || ''
l!l
07
MC/DC0%0/1
$c->on_delete || ''
$c->on_delete
Truth table50%1/2
A
A= $c->on_delete
Aresult
11
00
366  
367 7 my $def = "CONSTRAINT $name FOREIGN KEY ";
368  
369 7 ▶ if ( @fields ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fields) 7 0 7
370 7 $def .= '(' . join( ', ', @fields ) . ')';
371 }
372  
373 7 my $ref_table = quote($c->reference_table,$qt);
374  
375 7 $def .= " REFERENCES $ref_table";
376  
377 7 ▶ if ( @rfields ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rfields) 7 0 7
378 7 $def .= ' (' . join( ', ', @rfields ) . ')';
379 }
380  
381 7 ▶ if ( $c->match_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->match_type) 0 7 7
382 0 ▶ $def .= ' MATCH ' .
Branch: 1 branch
BranchTrueFalseTotal
' MATCH ' . $c->match_type =~ /full/i ? : 0 0 0
383 ( $c->match_type =~ /full/i ) ? 'FULL' : 'PARTIAL';
384 }
385  
386 7 ▶ if ( $on_delete && $on_delete ne "RESTRICT") {
Branch: 1 branch
BranchTrueFalseTotal
if ($on_delete and $on_delete ne "RESTRICT") 0 7 7
Condition33%1/3
$on_delete and $on_delete ne "RESTRICT"
!ll&&!rl&&r
700
MC/DC0%0/2
$on_delete and $on_delete ne "RESTRICT"
$on_delete $on_delete ne "RESTRICT"
Truth table33%1/3
A and B
A= $on_deleteB= $on_delete ne "RESTRICT"
ABresult
0X0
100
111
387 0 $def .= ' ON DELETE '.$c->on_delete;
388 }
389  
390 # disabled by plu 2007-12-29 - doesn't exist for oracle
391 #if ( $c->on_update ) {
392 # $def .= ' ON UPDATE '. $c->on_update;
393 #}
394  
395 7 push @fk_defs, sprintf("ALTER TABLE %s ADD %s", $table_name_q, $def);
396 }
397 }
398  
399 #
400 # Index Declarations
401 #
402 21 my @index_defs = ();
403 21 for my $index ( $table->get_indices ) {
404 11 ▶ my $index_name = $index->name || '';
Condition50%1/2
$index->name || ''
l!l
110
MC/DC0%0/1
$index->name || ''
$index->name
Truth table50%1/2
A
A= $index->name
Aresult
11
00
405 11 ▶ my $index_type = $index->type || NORMAL;
Condition50%1/2
$index->type || 'NORMAL'
l!l
110
MC/DC0%0/1
$index->type || 'NORMAL'
$index->type
Truth table50%1/2
A
A= $index->type
Aresult
11
00
406 11 my @fields = map { quote($_, $qf) } $index->fields;
407 11 ▶ next unless @fields;
Branch: 1 branch
BranchTrueFalseTotal
unless @fields 0 11 11
408  
409 11 my @index_options;
410 11 for my $opt ( $index->options ) {
411 3 ▶ if ( ref $opt eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opt eq "HASH") 3 0 3
412 3 my ( $key, $value ) = each %$opt;
413 3 ▶ if ( ref $value eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 3 3
elsif (not defined $value) { } 0 3 3
414 push @table_options, "$key\n(\n". join ("\n",
415 0 map { " $_->[0]\t$_->[1]" }
416 0 map { [ each %$_ ] }
417 @$value
418 )."\n)";
419 }
420 elsif ( !defined $value ) {
421 0 push @index_options, $key;
422 }
423 else {
424 3 push @index_options, "$key $value";
425 }
426 }
427 }
428 11 ▶ my $index_options = @index_options
Branch: 1 branch
BranchTrueFalseTotal
@index_options ? : 3 8 11
429 ? "\n".join("\n", @index_options) : '';
430  
431 11 ▶ if ( $index_type eq PRIMARY_KEY ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($index_type eq 'PRIMARY KEY') { } 0 11 11
elsif ($index_type eq 'NORMAL') { } 10 1 11
elsif ($index_type eq 'UNIQUE') { } 1 0 1
432 0 ▶ $index_name = $index_name ? mk_name( $index_name )
Branch: 1 branch
BranchTrueFalseTotal
$index_name ? : 0 0 0
433 : mk_name( $table_name, 'pk' );
434 0 $index_name = quote($index_name, $qf);
435 0 push @field_defs, 'CONSTRAINT '.$index_name.' PRIMARY KEY '.
436 '(' . join( ', ', @fields ) . ')';
437 }
438 elsif ( $index_type eq NORMAL ) {
439 10 ▶ $index_name = $index_name ? mk_name( $index_name )
Branch: 1 branch
BranchTrueFalseTotal
$index_name ? : 10 0 10
Condition0%0/2
$index_name || 'i'
l!l
00
MC/DC0%0/1
$index_name || 'i'
$index_name
Truth table0%0/2
A
A= $index_name
Aresult
11
00
440 : mk_name( $table_name, $index_name || 'i' );
441 10 $index_name = quote($index_name, $qf);
442 10 push @index_defs,
443 "CREATE INDEX $index_name on $table_name_q (".
444 join( ', ', @fields ).
445 ")$index_options";
446 }
447 elsif ( $index_type eq UNIQUE ) {
448 1 ▶ $index_name = $index_name ? mk_name( $index_name )
Branch: 1 branch
BranchTrueFalseTotal
$index_name ? : 1 0 1
Condition0%0/2
$index_name || 'i'
l!l
00
MC/DC0%0/1
$index_name || 'i'
$index_name
Truth table0%0/2
A
A= $index_name
Aresult
11
00
449 : mk_name( $table_name, $index_name || 'i' );
450 1 $index_name = quote($index_name, $qf);
451 1 push @index_defs,
452 "CREATE UNIQUE INDEX $index_name on $table_name_q (".
453 join( ', ', @fields ).
454 ")$index_options";
455 }
456 else {
457 0 ▶ warn "Unknown index type ($index_type) on table $table_name.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $SQL::Translator::Producer::Oracle::WARN 0 0 0
458 if $WARN;
459 }
460 }
461  
462 21 ▶ if ( my @table_comments = $table->comments ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@table_comments) = $table->comments) 0 21 21
463 0 for my $comment ( @table_comments ) {
464 0 ▶ next unless $comment;
Branch: 1 branch
BranchTrueFalseTotal
unless $comment 0 0 0
465 0 $comment = __PACKAGE__->_quote_string($comment);
466 push @field_comments, "COMMENT ON TABLE $table_name_q is\n $comment"
467 0 ▶ unless $options->{no_comments};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"no_comments"} 0 0 0
468 }
469 }
470  
471 21 ▶ my $table_options = @table_options
Branch: 1 branch
BranchTrueFalseTotal
@table_options ? : 5 16 21
472 ? "\n".join("\n", @table_options) : '';
473 push @create, "CREATE TABLE $table_name_q (\n" .
474 110 ▶ join( ",\n", map { " $_" } @field_defs,
Branch: 1 branch
BranchTrueFalseTotal
$options->{'delay_constraints'} ? : 2 19 21
475 21 ($options->{delay_constraints} ? () : @constraint_defs) ) .
476 "\n)$table_options";
477  
478 21 @constraint_defs = map { "ALTER TABLE $table_name_q ADD $_" }
479 @constraint_defs;
480  
481 21 ▶ if ( $WARN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SQL::Translator::Producer::Oracle::WARN) 0 21 21
482 0 ▶ if ( %truncated ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%truncated) 0 0 0
483 0 warn "Truncated " . keys( %truncated ) . " names:\n";
484 0 warn "\t" . join( "\n\t", sort keys %truncated ) . "\n";
485 }
486 }
487  
488 21 ▶ return \@create, \@fk_defs, \@trigger_defs, \@index_defs, ($options->{delay_constraints} ? \@constraint_defs : []);
Branch: 1 branch
BranchTrueFalseTotal
$options->{'delay_constraints'} ? : 2 19 21
489 }
490  
491 sub alter_field {
492 2 ▶ my ($from_field, $to_field, $options) = @_;
Subroutine alter_field: called CC=5 SCAR=16.8
Pod documented
493  
494 2 my $qt = $options->{quote_table_names};
495 2 my ($field_create, $field_defs, $trigger_defs, $field_comments) =
496 create_field($to_field, $options, {});
497  
498 # Fix ORA-01442
499 2 ▶ if ($to_field->is_nullable && !$from_field->is_nullable) {
Branch: 2 branches
BranchTrueFalseTotal
if ($to_field->is_nullable and not $from_field->is_nullable) { } 0 2 2
elsif (not $from_field->is_nullable || $to_field->is_nullable) { } 1 1 2
Condition33%1/3
$to_field->is_nullable and not $from_field->is_nullable
!ll&&!rl&&r
200
MC/DC0%0/2
$to_field->is_nullable and not $from_field->is_nullable
$to_field->is_nullable not $from_field->is_nullable
Truth table33%1/3
A and not(B)
A= $to_field->is_nullableB= not $from_field->is_nullable
ABresult
0X0
100
111
500 0 die 'Cannot remove NOT NULL from table field';
501 ▶ } elsif (!$from_field->is_nullable && !$to_field->is_nullable) {
Condition66%2/3
$from_field->is_nullable || $to_field->is_nullable
l!l&&r!l&&!r
101
MC/DC50%1/2
$from_field->is_nullable || $to_field->is_nullable
$from_field->is_nullable $to_field->is_nullable
Truth table66%2/3
A || B
A= $from_field->is_nullableB= $to_field->is_nullable
ABresult
1X1
011
000
502 1 @$field_defs = map { s/ NOT NULL//; $_} @$field_defs;
503 }
504  
505 2 my $table_name = quote($to_field->table->name,$qt);
506  
507 2 return 'ALTER TABLE '.$table_name.' MODIFY ( '.join('', @$field_defs).' )';
508 }
509  
510 sub add_field {
511 1 ▶ my ($new_field, $options) = @_;
Subroutine add_field: called CC=1 SCAR=0.0
Pod documented
512  
513 1 my $qt = $options->{quote_table_names};
514 1 my ($field_create, $field_defs, $trigger_defs, $field_comments) =
515 create_field($new_field, $options, {});
516  
517 1 my $table_name = quote($new_field->table->name,$qt);
518  
519 1 my $out = sprintf('ALTER TABLE %s ADD ( %s )',
520 $table_name,
521 join('', @$field_defs));
522 1 return $out;
523 }
524  
525 sub create_field {
526 87 ▶ my ($field, $options, $field_name_scope) = @_;
Subroutine create_field: called CC=44 SCAR=41.4
Pod documented
527 87 my $qf = $options->{quote_field_names};
528 87 my $qt = $options->{quote_table_names};
529  
530 87 my (@create, @field_defs, @trigger_defs, @field_comments);
531  
532 87 my $table_name = $field->table->name;
533 87 my $table_name_q = quote($table_name, $qt);
534  
535 #
536 # Field name
537 #
538 87 my $field_name = mk_name(
539 $field->name, '', $field_name_scope, 1
540 );
541 87 my $field_name_q = quote($field_name, $qf);
542 87 my $field_def = quote($field_name, $qf);
543 87 $field->name( $field_name );
544  
545 #
546 # Datatype
547 #
548 87 my $check;
549 87 my $data_type = lc $field->data_type;
550 87 my @size = $field->size;
551 87 my %extra = $field->extra;
552 87 ▶ my $list = $extra{'list'} || [];
Condition100%2/2
$extra{'list'} || []
l!l
186
MC/DC100%1/1
$extra{'list'} || []
$extra{'list'}
Truth table100%2/2
A
A= $extra{'list'}
Aresult
11
00
553 87 my $commalist = join( ', ', map { __PACKAGE__->_quote_string($_) } @$list );
554  
555 87 ▶ if ( $data_type eq 'enum' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data_type eq 'enum') { } 1 86 87
elsif ($data_type eq 'set') { } 0 86 86
556 1 $check = "CHECK ($field_name_q IN ($commalist))";
557 1 $data_type = 'varchar2';
558 }
559 elsif ( $data_type eq 'set' ) {
560 # XXX add a CHECK constraint maybe
561 # (trickier and slower, than enum :)
562 0 $data_type = 'varchar2';
563 }
564 else {
565 86 ▶ if (defined $translate{ $data_type }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $translate{$data_type}) 82 4 86
566 82 ▶ if (ref $translate{ $data_type } eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $translate{$data_type} eq 'ARRAY') { } 0 82 82
567 0 ($data_type,$size[0]) = @{$translate{ $data_type }};
568 } else {
569 82 $data_type = $translate{ $data_type };
570 }
571 }
572 86 ▶ $data_type ||= 'varchar2';
Condition50%1/2
$data_type ||= "varchar2"
l!l
860
MC/DC0%0/1
$data_type ||= "varchar2"
$data_type
Truth table50%1/2
A
A= $data_type
Aresult
11
00
573 }
574  
575 # ensure size is not bigger than max size oracle allows for data type
576 87 ▶ if ( defined $max_size{$data_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max_size{$data_type}) 73 14 87
577 73 ▶ for ( my $i = 0 ; $i < scalar @size ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @size) 81 73 154
578 my $max =
579 ref( $max_size{$data_type} ) eq 'ARRAY'
580 ? $max_size{$data_type}->[$i]
581 81 ▶ : $max_size{$data_type};
Branch: 1 branch
BranchTrueFalseTotal
ref $max_size{$data_type} eq 'ARRAY' ? : 41 40 81
582 81 ▶ $size[$i] = $max if $size[$i] > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $size[$i] > $max 0 81 81
583 }
584 }
585  
586 #
587 # Fixes ORA-02329: column of datatype LOB cannot be
588 # unique or a primary key
589 #
590 87 ▶ if ( $data_type eq 'clob' && $field->is_primary_key ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_type eq "clob" and $field->is_primary_key) 1 86 87
Condition100%3/3
$data_type eq "clob" and $field->is_primary_key
!ll&&!rl&&r
8061
MC/DC100%2/2
$data_type eq "clob" and $field->is_primary_key
$data_type eq "clob" $field->is_primary_key
Truth table100%3/3
A and B
A= $data_type eq "clob"B= $field->is_primary_key
ABresult
0X0
100
111
591 1 $data_type = 'varchar2';
592 1 $size[0] = 4000;
593 1 ▶ warn "CLOB cannot be a primary key, changing to VARCHAR2\n"
Branch: 1 branch
BranchTrueFalseTotal
if $SQL::Translator::Producer::Oracle::WARN 0 1 1
594 if $WARN;
595 }
596  
597 87 ▶ if ( $data_type eq 'clob' && $field->is_unique ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_type eq "clob" and $field->is_unique) 0 87 87
Condition66%2/3
$data_type eq "clob" and $field->is_unique
!ll&&!rl&&r
8160
MC/DC0%0/2
$data_type eq "clob" and $field->is_unique
$data_type eq "clob" $field->is_unique
Truth table66%2/3
A and B
A= $data_type eq "clob"B= $field->is_unique
ABresult
0X0
100
111
598 0 $data_type = 'varchar2';
599 0 $size[0] = 4000;
600 0 ▶ warn "CLOB cannot be a unique key, changing to VARCHAR2\n"
Branch: 1 branch
BranchTrueFalseTotal
if $SQL::Translator::Producer::Oracle::WARN 0 0 0
601 if $WARN;
602 }
603  
604 #
605 # Fixes ORA-00907: missing right parenthesis
606 #
607 87 ▶ if ( $data_type =~ /(date|clob)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_type =~ /(date|clob)/i) 13 74 87
608 13 undef @size;
609 }
610  
611 #
612 # Fixes ORA-00906: missing right parenthesis
613 # if size is 0 or undefined
614 #
615 87 for (qw/varchar2/) {
616 87 ▶ if ( $data_type =~ /^($_)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_type =~ /^($_)$/i) 38 49 87
617 38 ▶ $size[0] ||= $max_size{$_};
Condition66%2/3
$size[0] ||= $max_size{$_}
l!l&&r!l&&!r
23150
MC/DC0%0/2
$size[0] ||= $max_size{$_}
$size[0] $max_size{$_}
Truth table66%2/3
A ||= B
A= $size[0]B= $max_size{$_}
ABresult
1X1
011
000
618 }
619 }
620  
621 87 $field_def .= " $data_type";
622 87 ▶ if ( defined $size[0] && $size[0] > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $size[0] and $size[0] > 0) 71 16 87
Condition100%3/3
defined $size[0] and $size[0] > 0
!ll&&!rl&&r
13371
MC/DC100%2/2
defined $size[0] and $size[0] > 0
defined $size[0] $size[0] > 0
Truth table100%3/3
A and B
A= defined $size[0]B= $size[0] > 0
ABresult
0X0
100
111
623 71 $field_def .= '(' . join( ',', @size ) . ')';
624 }
625  
626 #
627 # Default value
628 #
629 87 my $default = $field->default_value;
630 87 ▶ if ( defined $default ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $default) 35 52 87
631 #
632 # Wherein we try to catch a string being used as
633 # a default value for a numerical field. If "true/false,"
634 # then sub "1/0," otherwise just test the truthity of the
635 # argument and use that (naive?).
636 #
637 35 ▶ if (ref $default and defined $$default) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $default and defined $$default) { } 0 35 35
elsif (ref $default) { } 0 35 35
elsif ($data_type =~ /^number$/i and not $default =~ /^-?\d+$/ and not $default =~ /null/i) { } 1 34 35
elsif ($data_type =~ /date/ and $default eq 'current_timestamp' || $default eq 'now()') { } 0 34 34
Condition33%1/3
ref $default and defined $$default
!ll&&!rl&&r
3500
MC/DC0%0/2
ref $default and defined $$default
ref $default defined $$default
Truth table33%1/3
A and B
A= ref $defaultB= defined $$default
ABresult
0X0
100
111
638 0 $default = $$default;
639 } elsif (ref $default) {
640 0 $default = 'NULL';
641 ▶ } elsif (
Condition83%5/6
$data_type =~ /^number$/i and not $default =~ /^-?\d+$/ and not $default =~ /null/i
!ll&&!rl&&r
3401
$data_type =~ /^number$/i and not $default =~ /^-?\d+$/
!ll&&!rl&&r
2771
MC/DC66%2/3
$data_type =~ /^number$/i and not $default =~ /^-?\d+$/ and not $default =~ /null/i
$data_type =~ /^number$/i not $default =~ /^-?\d+$/ not $default =~ /null/i
Truth table75%3/4
A and not(B) and not(C)
A= $data_type =~ /^number$/iB= not $default =~ /^-?\d+$/C= not $default =~ /null/i
ABCresult
0XX0
10X0
1100
1111
642 $data_type =~ /^number$/i &&
643 $default !~ /^-?\d+$/ &&
644 $default !~ m/null/i
645 ) {
646 1 ▶ if ( $default =~ /^true$/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($default =~ /^true$/i) { } 0 1 1
elsif ($default =~ /^false$/i) { } 0 1 1
647 0 $default = "'1'";
648 } elsif ( $default =~ /^false$/i ) {
649 0 $default = "'0'";
650 } else {
651 1 ▶ $default = $default ? "'1'" : "'0'";
Branch: 1 branch
BranchTrueFalseTotal
$default ? : 1 0 1
652 }
653 ▶ } elsif (
Condition16%1/6
$data_type =~ /date/ and $default eq "current_timestamp" || $default eq "now()"
!ll&&!rl&&r
3400
$default eq "current_timestamp" or $default eq "now()"
l!l&&r!l&&!r
000
MC/DC0%0/3
$data_type =~ /date/ and $default eq "current_timestamp" || $default eq "now()"
$data_type =~ /date/ $default eq "current_timestamp" $default eq "now()"
Truth table25%1/4
A and B or C
A= $data_type =~ /date/B= $default eq "current_timestamp"C= $default eq "now()"
ABCresult
0XX0
1000
11X1
1011
654 $data_type =~ /date/ && (
655 $default eq 'current_timestamp'
656 ||
657 $default eq 'now()'
658 )
659 ) {
660 0 $default = 'SYSDATE';
661 } else {
662 34 ▶ $default = $default =~ m/null/i ? 'NULL' : __PACKAGE__->_quote_string($default);
Branch: 1 branch
BranchTrueFalseTotal
$default =~ /null/i ? : 0 34 34
663 }
664  
665 35 $field_def .= " DEFAULT $default",
666 }
667  
668 #
669 # Not null constraint
670 #
671 87 ▶ unless ( $field->is_nullable ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($field->is_nullable) 35 52 87
672 35 $field_def .= ' NOT NULL';
673 }
674  
675 87 ▶ $field_def .= " $check" if $check;
Branch: 1 branch
BranchTrueFalseTotal
if $check 1 86 87
676  
677 #
678 # Auto_increment
679 #
680 87 ▶ if ( $field->is_auto_increment ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->is_auto_increment) 15 72 87
681 15 my $base_name = $table_name . "_". $field_name;
682 15 my $seq_name = quote(mk_name( $base_name, 'sq' ),$qt);
683 15 my $trigger_name = quote(mk_name( $base_name, 'ai' ),$qt);
684  
685 15 ▶ push @create, qq[DROP SEQUENCE $seq_name] if $options->{add_drop_table};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"add_drop_table"} 11 4 15
686 15 push @create, "CREATE SEQUENCE $seq_name";
687 15 my $trigger =
688 "CREATE OR REPLACE TRIGGER $trigger_name\n" .
689 "BEFORE INSERT ON $table_name_q\n" .
690 "FOR EACH ROW WHEN (\n" .
691 " new.$field_name_q IS NULL".
692 " OR new.$field_name_q = 0\n".
693 ")\n".
694 "BEGIN\n" .
695 " SELECT $seq_name.nextval\n" .
696 " INTO :new." . $field_name_q."\n" .
697 " FROM dual;\n" .
698 "END;\n";
699  
700 15 push @trigger_defs, $trigger;
701 }
702  
703 87 ▶ if ( lc $field->data_type eq 'timestamp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $field->data_type eq "timestamp") 6 81 87
704 6 my $base_name = $table_name . "_". $field_name;
705 6 my $trig_name = quote(mk_name( $base_name, 'ts' ), $qt);
706 6 my $trigger =
707 "CREATE OR REPLACE TRIGGER $trig_name\n".
708 "BEFORE INSERT OR UPDATE ON $table_name_q\n".
709 "FOR EACH ROW WHEN (new.$field_name_q IS NULL)\n".
710 "BEGIN\n".
711 " SELECT sysdate INTO :new.$field_name_q FROM dual;\n".
712 "END;\n";
713  
714 6 push @trigger_defs, $trigger;
715 }
716  
717 87 push @field_defs, $field_def;
718  
719 87 ▶ if ( my $comment = $field->comments ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $comment = $field->comments) 5 82 87
720 5 $comment =~ __PACKAGE__->_quote_string($comment);
721 push @field_comments,
722 "COMMENT ON COLUMN $table_name_q.$field_name_q is\n $comment;"
723 5 ▶ unless $options->{no_comments};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"no_comments"} 0 5 5
724 }
725  
726 87 return \@create, \@field_defs, \@trigger_defs, \@field_comments;
727  
728 }
729  
730  
731 sub create_view {
732 6 ▶ my ($view, $options) = @_;
Subroutine create_view: called CC=3 SCAR=11.0
Pod documented
733 6 my $qt = $options->{quote_table_names};
734 6 my $view_name = quote($view->name,$qt);
735 6 my $extra = $view->extra;
736  
737 6 my $view_type = 'VIEW';
738 6 my $view_options = '';
739 6 ▶ if ( my $materialized = $extra->{materialized} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $materialized = $extra->{"materialized"}) 1 5 6
740 1 $view_type = 'MATERIALIZED VIEW';
741 1 $view_options .= ' '.$materialized;
742 }
743  
744 6 my @create;
745 push @create, qq[DROP $view_type $view_name]
746 6 ▶ if $options->{add_drop_view};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"add_drop_view"} 5 1 6
747  
748 6 push @create, sprintf("CREATE %s %s%s AS\n%s",
749 $view_type,
750 $view_name,
751 $view_options,
752 $view->sql);
753  
754 6 return \@create;
755 }
756  
757 sub mk_name {
758 153 ▶ my $basename = shift || '';
Subroutine mk_name: called CC=17 SCAR=30.0
Pod undocumented
Condition50%1/2
shift() || ''
l!l
1530
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
759 153 ▶ my $type = shift || '';
Condition100%2/2
shift() || ''
l!l
48105
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
760 153 ▶ $type = '' if $type =~ /^\d/;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /^\d/ 0 153 153
761 153 ▶ my $scope = shift || '';
Condition100%2/2
shift() || ''
l!l
8766
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
762 153 ▶ my $critical = shift || '';
Condition100%2/2
shift() || ''
l!l
8766
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
763 153 my $basename_orig = $basename;
764 153 ▶ my $max_name = $type
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 48 105 153
765 ? $max_id_length - (length($type) + 1)
766 : $max_id_length;
767 153 ▶ $basename = substr( $basename, 0, $max_name )
Branch: 1 branch
BranchTrueFalseTotal
if length $basename > $max_name 7 146 153
768 if length( $basename ) > $max_name;
769 153 ▶ my $name = $type ? "${type}_$basename" : $basename;
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 48 105 153
770  
771 153 ▶ if ( $basename ne $basename_orig and $critical ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($basename ne $basename_orig and $critical) 0 153 153
Condition66%2/3
$basename ne $basename_orig and $critical
!ll&&!rl&&r
14670
MC/DC0%0/2
$basename ne $basename_orig and $critical
$basename ne $basename_orig $critical
Truth table66%2/3
A and B
A= $basename ne $basename_origB= $critical
ABresult
0X0
100
111
772 0 ▶ my $show_type = $type ? "+'$type'" : "";
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 0 0 0
773 0 ▶ warn "Truncating '$basename_orig'$show_type to $max_id_length ",
Branch: 1 branch
BranchTrueFalseTotal
if $SQL::Translator::Producer::Oracle::WARN 0 0 0
774 "character limit to make '$name'\n" if $WARN;
775 0 $truncated{ $basename_orig } = $name;
776 }
777  
778 153 ▶ $scope ||= \%global_names;
Condition100%2/2
$scope ||= \%global_names
l!l
8766
MC/DC100%1/1
$scope ||= \%global_names
$scope
Truth table100%2/2
A
A= $scope
Aresult
11
00
779 153 ▶ if ( my $prev = $scope->{ $name } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $prev = $scope->{$name}) 20 133 153
780 20 my $name_orig = $name;
781 20 ▶ substr($name, $max_id_length - 2) = ""
Branch: 1 branch
BranchTrueFalseTotal
if length $name >= $max_id_length - 1 2 18 20
782 if length( $name ) >= $max_id_length - 1;
783 20 $name .= sprintf( "%02d", $prev++ );
784  
785 20 ▶ warn "The name '$name_orig' has been changed to ",
Branch: 1 branch
BranchTrueFalseTotal
if $SQL::Translator::Producer::Oracle::WARN 0 20 20
786 "'$name' to make it unique.\n" if $WARN;
787  
788 20 $scope->{ $name_orig }++;
789 }
790  
791 153 $scope->{ $name }++;
792 153 return $name;
793 }
794  
795 10 1;
796  
797 sub quote {
798 436 ▶ my ($name, $q) = @_;
Subroutine quote: called CC=3 SCAR=11.0
Pod undocumented
799 436 ▶ return $name unless $q && $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $q and $name 183 253 436
Condition100%3/3
$q and $name
!ll&&!rl&&r
17211253
MC/DC100%2/2
$q and $name
$q $name
Truth table100%3/3
A and B
A= $qB= $name
ABresult
0X0
100
111
800 253 $name =~ s/\Q$quote_char/$quote_char$quote_char/g;
801 253 return "$quote_char$name$quote_char";
802 }
803  
804  
805 # -------------------------------------------------------------------
806 # All bad art is the result of good intentions.
807 # Oscar Wilde
808 # -------------------------------------------------------------------
809  
810 =pod
811  
812 =head1 CREDITS
813  
814 Mad props to Tim Bunce for much of the logic stolen from his "mysql2ora"
815 script.
816  
817 =head1 AUTHORS
818  
819 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>,
820 Alexander Hartmaier E<lt>abraxxa@cpan.orgE<gt>,
821 Fabien Wernli E<lt>faxmodem@cpan.orgE<gt>.
822  
823 =head1 SEE ALSO
824  
825 SQL::Translator, DDL::Oracle, mysql2ora.
826  
827 =cut
« blib/lib/SQL/Translator/Parser/DBI/SQLServer.pm ↑ Summary blib/lib/SQL/Translator/Parser/DBI/Sybase.pm »