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

filter: Statementstmt 85.0% 136 / 160 Branchbran 59.7% 55 / 92 Conditioncond 53.0% 26 / 49 MC/DCmcdc 24.1% 7 / 29 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 68.0% 232 / 341 SCAR 52.2
CC
72
Cov
72%
produce
107.7
mk_name
43.9
unreserve
7.0
CRAP 184.7
« blib/lib/SQL/Translator/Producer/MySQL.pm ↑ Summary blib/lib/SQL/Translator/Schema.pm »
1 package SQL::Translator::Producer::Sybase;
2  
3 =head1 NAME
4  
5 SQL::Translator::Producer::Sybase - Sybase producer for SQL::Translator
6  
7 =head1 SYNOPSIS
8  
9 use SQL::Translator;
10  
11 my $t = SQL::Translator->new( parser => '...', producer => 'Sybase' );
12 $t->translate;
13  
14 =head1 DESCRIPTION
15  
16 This module will produce text output of the schema suitable for Sybase.
17  
18 =cut
19  
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 our ( $DEBUG, $WARN );
23 1 our $VERSION = '1.63';
24 1 ▶$DEBUG = 1 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $SQL::Translator::Producer::Sybase::DEBUG 1 0 1
25  
26 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use SQL::Translator::Schema::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use SQL::Translator::Utils qw(debug header_comment);
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 my %translate = (
31 #
32 # Sybase types
33 #
34 integer => 'numeric',
35 int => 'numeric',
36 number => 'numeric',
37 money => 'money',
38 varchar => 'varchar',
39 varchar2 => 'varchar',
40 timestamp => 'datetime',
41 text => 'varchar',
42 real => 'double precision',
43 comment => 'text',
44 bit => 'bit',
45 tinyint => 'smallint',
46 float => 'double precision',
47 serial => 'numeric',
48 boolean => 'varchar',
49 char => 'char',
50 long => 'varchar',
51 );
52  
53 1 my %reserved = map { $_, 1 } qw[
54 ALL ANALYSE ANALYZE AND ANY AS ASC
55 BETWEEN BINARY BOTH
56 CASE CAST CHECK COLLATE COLUMN CONSTRAINT CROSS
57 CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER
58 DEFAULT DEFERRABLE DESC DISTINCT DO
59 ELSE END EXCEPT
60 FALSE FOR FOREIGN FREEZE FROM FULL
61 GROUP HAVING
62 ILIKE IN INITIALLY INNER INTERSECT INTO IS ISNULL
63 JOIN LEADING LEFT LIKE LIMIT
64 NATURAL NEW NOT NOTNULL NULL
65 OFF OFFSET OLD ON ONLY OR ORDER OUTER OVERLAPS
66 PRIMARY PUBLIC REFERENCES RIGHT
67 SELECT SESSION_USER SOME TABLE THEN TO TRAILING TRUE
68 UNION UNIQUE USER USING VERBOSE WHEN WHERE
69 ];
70  
71 1 my $max_id_length = 30;
72 1 my %used_identifiers = ();
73 1 my %global_names;
74 my %unreserve;
75 1 my %truncated;
76  
77 =pod
78  
79 =head1 Sybase Create Table Syntax
80  
81 CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name (
82 { column_name data_type [ DEFAULT default_expr ] [ column_constraint [, ... ] ]
83 | table_constraint } [, ... ]
84 )
85 [ INHERITS ( parent_table [, ... ] ) ]
86 [ WITH OIDS | WITHOUT OIDS ]
87  
88 where column_constraint is:
89  
90 [ CONSTRAINT constraint_name ]
91 { NOT NULL | NULL | UNIQUE | PRIMARY KEY |
92 CHECK (expression) |
93 REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL ]
94 [ ON DELETE action ] [ ON UPDATE action ] }
95 [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
96  
97 and table_constraint is:
98  
99 [ CONSTRAINT constraint_name ]
100 { UNIQUE ( column_name [, ... ] ) |
101 PRIMARY KEY ( column_name [, ... ] ) |
102 CHECK ( expression ) |
103 FOREIGN KEY ( column_name [, ... ] ) REFERENCES reftable [ ( refcolumn [, ... ] ) ]
104 [ MATCH FULL | MATCH PARTIAL ] [ ON DELETE action ] [ ON UPDATE action ] }
105 [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
106  
107 =head1 Create Index Syntax
108  
109 CREATE [ UNIQUE ] INDEX index_name ON table
110 [ USING acc_method ] ( column [ ops_name ] [, ...] )
111 [ WHERE predicate ]
112 CREATE [ UNIQUE ] INDEX index_name ON table
113 [ USING acc_method ] ( func_name( column [, ... ]) [ ops_name ] )
114 [ WHERE predicate ]
115  
116 =cut
117  
118 sub produce {
119 1 ▶ my $translator = shift;
Subroutine produce: called CC=49 SCAR=46.8
Pod undocumented
120 1 $DEBUG = $translator->debug;
121 1 $WARN = $translator->show_warnings;
122 1 my $no_comments = $translator->no_comments;
123 1 my $add_drop_table = $translator->add_drop_table;
124 1 my $schema = $translator->schema;
125  
126 1 my @output;
127 1 ▶ push @output, header_comment unless ($no_comments);
Branch: 1 branch
BranchTrueFalseTotal
unless $no_comments 0 1 1
128  
129 1 my @foreign_keys;
130  
131 1 for my $table ( $schema->get_tables ) {
132 4 ▶ my $table_name = $table->name or next;
Branch: 1 branch
BranchTrueFalseTotal
my $table_name = $table->name or next 0 4 4
133 4 $table_name = mk_name( $table_name, '', undef, 1 );
134 4 ▶ my $table_name_ur = unreserve($table_name) || '';
Condition50%1/2
unreserve($table_name) || ''
l!l
40
MC/DC0%0/1
unreserve($table_name) || ''
unreserve($table_name)
Truth table50%1/2
A
A= unreserve($table_name)
Aresult
11
00
135  
136 4 my ( @comments, @field_defs, @index_defs, @constraint_defs );
137  
138 4 ▶ push @comments, "--\n-- Table: $table_name_ur\n--" unless $no_comments;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_comments 0 4 4
139  
140 4 push @comments, map { "-- $_" } $table->comments;
141  
142 #
143 # Fields
144 #
145 4 my %field_name_scope;
146 4 for my $field ( $table->get_fields ) {
147 14 my $field_name = mk_name(
148 $field->name, '', \%field_name_scope, undef,1
149 );
150 14 my $field_name_ur = unreserve( $field_name, $table_name );
151 14 my $field_def = qq["$field_name_ur"];
152 14 $field_def =~ s/\"//g;
153 14 ▶ if ( $field_def =~ /identity/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($field_def =~ /identity/) 0 14 14
154 0 $field_def =~ s/identity/pidentity/;
155 }
156  
157 #
158 # Datatype
159 #
160 14 my $data_type = lc $field->data_type;
161 14 my $orig_data_type = $data_type;
162 14 my %extra = $field->extra;
163 14 ▶ my $list = $extra{'list'} || [];
Condition50%1/2
$extra{'list'} || []
l!l
014
MC/DC0%0/1
$extra{'list'} || []
$extra{'list'}
Truth table50%1/2
A
A= $extra{'list'}
Aresult
11
00
164 # \todo deal with embedded quotes
165 14 my $commalist = join( ', ', map { qq['$_'] } @$list );
166 14 my $seq_name;
167  
168 14 my $identity = '';
169  
170 14 ▶ if ( $data_type eq 'enum' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data_type eq 'enum') { } 0 14 14
elsif ($data_type eq 'set') { } 0 14 14
171 0 my $check_name = mk_name(
172 $table_name.'_'.$field_name, 'chk' ,undef, 1
173 );
174 0 push @constraint_defs,
175 "CONSTRAINT $check_name CHECK ($field_name IN ($commalist))";
176 0 $data_type .= 'character varying';
177 }
178 elsif ( $data_type eq 'set' ) {
179 0 $data_type .= 'character varying';
180 }
181 else {
182 14 ▶ if ( $field->is_auto_increment ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->is_auto_increment) 3 11 14
183 3 $identity = 'IDENTITY';
184 }
185 14 ▶ if ( defined $translate{ $data_type } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $translate{$data_type}) { } 12 2 14
186 12 $data_type = $translate{ $data_type };
187 }
188 else {
189 2 ▶ warn "Unknown datatype: $data_type ",
Branch: 1 branch
BranchTrueFalseTotal
if $SQL::Translator::Producer::Sybase::WARN 0 2 2
190 "($table_name.$field_name)\n" if $WARN;
191 }
192 }
193  
194 14 my $size = $field->size;
195 14 ▶ unless ( $size ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($size) 3 11 14
196 3 ▶ if ( $data_type =~ /numeric/ ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($data_type =~ /numeric/) { } 0 3 3
elsif ($orig_data_type eq 'text') { } 2 1 3
elsif ($data_type eq 'varchar' and $orig_data_type eq 'boolean') { } 0 1 1
elsif ($data_type eq 'varchar') { } 0 1 1
197 0 $size = '9,0';
198 }
199 elsif ( $orig_data_type eq 'text' ) {
200 #interpret text fields as long varchars
201 2 $size = '255';
202 }
203 ▶ elsif (
Condition33%1/3
$data_type eq "varchar" and $orig_data_type eq "boolean"
!ll&&!rl&&r
100
MC/DC0%0/2
$data_type eq "varchar" and $orig_data_type eq "boolean"
$data_type eq "varchar" $orig_data_type eq "boolean"
Truth table33%1/3
A and B
A= $data_type eq "varchar"B= $orig_data_type eq "boolean"
ABresult
0X0
100
111
204 $data_type eq 'varchar' &&
205 $orig_data_type eq 'boolean'
206 ) {
207 0 $size = '6';
208 }
209 elsif ( $data_type eq 'varchar' ) {
210 0 $size = '255';
211 }
212 }
213  
214 14 $field_def .= " $data_type";
215 14 ▶ $field_def .= "($size)" if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 13 1 14
216 14 ▶ $field_def .= " $identity" if $identity;
Branch: 1 branch
BranchTrueFalseTotal
if $identity 3 11 14
217  
218 #
219 # Default value
220 #
221 14 my $default = $field->default_value;
222 14 ▶ if ( defined $default ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $default) 7 7 14
223 7 ▶ $field_def .= sprintf( ' DEFAULT %s',
Branch: 2 branches
BranchTrueFalseTotal
$field->is_auto_increment && $seq_name ? : 0 7 7
$default =~ /null/i ? : 0 7 7
Condition33%1/3
$field->is_auto_increment and $seq_name
!ll&&!rl&&r
700
MC/DC0%0/2
$field->is_auto_increment and $seq_name
$field->is_auto_increment $seq_name
Truth table33%1/3
A and B
A= $field->is_auto_incrementB= $seq_name
ABresult
0X0
100
111
224 ( $field->is_auto_increment && $seq_name )
225 ? qq[nextval('"$seq_name"'::text)] :
226 ( $default =~ m/null/i ) ? 'NULL' : "'$default'"
227 );
228 }
229  
230 #
231 # Not null constraint
232 #
233 14 ▶ unless ( $field->is_nullable ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->is_nullable) { } 9 5 14
234 5 $field_def .= ' NOT NULL';
235 }
236 else {
237 9 ▶ $field_def .= ' NULL' if $data_type ne 'bit';
Branch: 1 branch
BranchTrueFalseTotal
if $data_type ne "bit" 9 0 9
238 }
239  
240 14 push @field_defs, $field_def;
241 }
242  
243 #
244 # Constraint Declarations
245 #
246 4 my @constraint_decs = ();
247 4 my $c_name_default;
248 4 for my $constraint ( $table->get_constraints ) {
249 5 ▶ my $name = $constraint->name || '';
Condition100%2/2
$constraint->name || ''
l!l
23
MC/DC100%1/1
$constraint->name || ''
$constraint->name
Truth table100%2/2
A
A= $constraint->name
Aresult
11
00
250 5 ▶ my $type = $constraint->type || NORMAL;
Condition50%1/2
$constraint->type || 'NORMAL'
l!l
50
MC/DC0%0/1
$constraint->type || 'NORMAL'
$constraint->type
Truth table50%1/2
A
A= $constraint->type
Aresult
11
00
251 5 my @fields = map { unreserve( $_, $table_name ) }
252 $constraint->fields;
253 5 my @rfields = map { unreserve( $_, $table_name ) }
254 $constraint->reference_fields;
255 5 ▶ next unless @fields;
Branch: 1 branch
BranchTrueFalseTotal
unless @fields 0 5 5
256  
257 5 ▶ if ( $type eq PRIMARY_KEY ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'PRIMARY KEY') { } 3 2 5
elsif ($type eq 'FOREIGN KEY') { } 1 1 2
elsif ($type eq 'UNIQUE') { } 1 0 1
258 3 ▶ $name ||= mk_name( $table_name, 'pk', undef,1 );
Condition33%1/3
$name ||= mk_name($table_name, "pk", undef, 1)
l!l&&r!l&&!r
030
MC/DC0%0/2
$name ||= mk_name($table_name, "pk", undef, 1)
$name mk_name($table_name, "pk", undef, 1)
Truth table33%1/3
A ||= B
A= $nameB= mk_name($table_name, "pk", undef, 1)
ABresult
1X1
011
000
259 3 push @constraint_defs,
260 "CONSTRAINT $name PRIMARY KEY ".
261 '(' . join( ', ', @fields ) . ')';
262 }
263 elsif ( $type eq FOREIGN_KEY ) {
264 1 ▶ $name ||= mk_name( $table_name, 'fk', undef,1 );
Condition33%1/3
$name ||= mk_name($table_name, "fk", undef, 1)
l!l&&r!l&&!r
100
MC/DC0%0/2
$name ||= mk_name($table_name, "fk", undef, 1)
$name mk_name($table_name, "fk", undef, 1)
Truth table33%1/3
A ||= B
A= $nameB= mk_name($table_name, "fk", undef, 1)
ABresult
1X1
011
000
265 1 push @foreign_keys,
266 "ALTER TABLE $table ADD CONSTRAINT $name FOREIGN KEY".
267 ' (' . join( ', ', @fields ) . ') REFERENCES '.
268 $constraint->reference_table.
269 ' (' . join( ', ', @rfields ) . ')';
270 }
271 elsif ( $type eq UNIQUE ) {
272 1 ▶ $name ||= mk_name(
Condition16%1/6
$name ||= mk_name($table_name, $name || ++$c_name_default, undef, 1)
l!l&&r!l&&!r
100
$name || ++$c_name_default
l!l&&r!l&&!r
000
MC/DC0%0/2
$name ||= mk_name($table_name, $name || ++$c_name_default, undef, 1)
$name mk_name($table_name, $name || ++$c_name_default, undef, 1)
MC/DC0%0/2
$name || ++$c_name_default
$name ++$c_name_default
Truth table33%1/3
A ||= B
A= $nameB= mk_name($table_name, $name || ++$c_name_default, undef, 1)
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $nameB= ++$c_name_default
ABresult
1X1
011
000
273 $table_name,
274 $name || ++$c_name_default,undef, 1
275 );
276 1 push @constraint_defs,
277 "CONSTRAINT $name UNIQUE " .
278 '(' . join( ', ', @fields ) . ')';
279 }
280 }
281  
282 #
283 # Indices
284 #
285 4 for my $index ( $table->get_indices ) {
286 1 push @index_defs,
287 'CREATE INDEX ' . $index->name .
288 " ON $table_name (".
289 join( ', ', $index->fields ) . ")";
290 }
291  
292 4 ▶ my $drop_statement = $add_drop_table
Branch: 1 branch
BranchTrueFalseTotal
$add_drop_table ? : 4 0 4
293 ? qq[DROP TABLE $table_name_ur] : '';
294 my $create_statement = qq[CREATE TABLE $table_name_ur (\n].
295 join( ",\n",
296 4 map { " $_" } @field_defs, @constraint_defs
297 ).
298 "\n)"
299 ;
300  
301 4 $create_statement = join("\n\n", @comments) . "\n\n" . $create_statement;
302 4 push @output,
303 $create_statement,
304 @index_defs,
305 ;
306 }
307  
308 1 foreach my $view ( $schema->get_views ) {
309 1 my (@comments, $view_name);
310  
311 1 $view_name = $view->name();
312 1 ▶ push @comments, "--\n-- View: $view_name\n--" unless $no_comments;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_comments 0 1 1
313  
314 # text of view is already a 'create view' statement so no need
315 # to do anything fancy.
316  
317 1 push @output, join("\n\n",
318 @comments,
319 $view->sql(),
320 );
321 }
322  
323  
324 1 foreach my $procedure ( $schema->get_procedures ) {
325 1 my (@comments, $procedure_name);
326  
327 1 $procedure_name = $procedure->name();
328 1 ▶ push @comments,
Branch: 1 branch
BranchTrueFalseTotal
unless $no_comments 0 1 1
329 "--\n-- Procedure: $procedure_name\n--" unless $no_comments;
330  
331 # text of procedure already has the 'create procedure' stuff
332 # so there is no need to do anything fancy. However, we should
333 # think about doing fancy stuff with granting permissions and
334 # so on.
335  
336 1 push @output, join("\n\n",
337 @comments,
338 $procedure->sql(),
339 );
340 }
341 1 push @output, @foreign_keys;
342  
343 1 ▶ if ( $WARN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SQL::Translator::Producer::Sybase::WARN) 0 1 1
344 0 ▶ if ( %truncated ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%truncated) 0 0 0
345 0 warn "Truncated " . keys( %truncated ) . " names:\n";
346 0 warn "\t" . join( "\n\t", sort keys %truncated ) . "\n";
347 }
348  
349 0 ▶ if ( %unreserve ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%unreserve) 0 0 0
350 0 warn "Encounted " . keys( %unreserve ) .
351 " unsafe names in schema (reserved or invalid):\n";
352 0 warn "\t" . join( "\n\t", sort keys %unreserve ) . "\n";
353 }
354 }
355  
356 1 ▶ return wantarray ? @output : join ";\n\n", @output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
357 }
358  
359 sub mk_name {
360 21 ▶ my $basename = shift || '';
Subroutine mk_name: called CC=18 SCAR=37.8
Pod undocumented
Condition50%1/2
shift() || ''
l!l
210
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
361 21 ▶ my $type = shift || '';
Condition100%2/2
shift() || ''
l!l
318
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
362 21 ▶ my $scope = shift || '';
Condition100%2/2
shift() || ''
l!l
147
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
363 21 ▶ my $critical = shift || '';
Condition100%2/2
shift() || ''
l!l
714
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
364 21 my $basename_orig = $basename;
365 21 ▶ my $max_name = $type
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 3 18 21
366 ? $max_id_length - (length($type) + 1)
367 : $max_id_length;
368 21 ▶ $basename = substr( $basename, 0, $max_name )
Branch: 1 branch
BranchTrueFalseTotal
if length $basename > $max_name 0 21 21
369 if length( $basename ) > $max_name;
370 21 ▶ my $name = $type ? "${type}_$basename" : $basename;
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 3 18 21
371  
372 21 ▶ if ( $basename ne $basename_orig and $critical ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($basename ne $basename_orig and $critical) 0 21 21
Condition33%1/3
$basename ne $basename_orig and $critical
!ll&&!rl&&r
2100
MC/DC0%0/2
$basename ne $basename_orig and $critical
$basename ne $basename_orig $critical
Truth table33%1/3
A and B
A= $basename ne $basename_origB= $critical
ABresult
0X0
100
111
373 0 ▶ my $show_type = $type ? "+'$type'" : "";
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 0 0 0
374 0 ▶ warn "Truncating '$basename_orig'$show_type to $max_id_length ",
Branch: 1 branch
BranchTrueFalseTotal
if $SQL::Translator::Producer::Sybase::WARN 0 0 0
375 "character limit to make '$name'\n" if $WARN;
376 0 $truncated{ $basename_orig } = $name;
377 }
378  
379 21 ▶ $scope ||= \%global_names;
Condition100%2/2
$scope ||= \%global_names
l!l
147
MC/DC100%1/1
$scope ||= \%global_names
$scope
Truth table100%2/2
A
A= $scope
Aresult
11
00
380 21 ▶ if ( my $prev = $scope->{ $name } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $prev = $scope->{$name}) 0 21 21
381 0 my $name_orig = $name;
382 0 $name .= sprintf( "%02d", ++$prev );
383 0 ▶ substr($name, $max_id_length - 3) = "00"
Branch: 1 branch
BranchTrueFalseTotal
if length $name > $max_id_length 0 0 0
384 if length( $name ) > $max_id_length;
385  
386 0 ▶ warn "The name '$name_orig' has been changed to ",
Branch: 1 branch
BranchTrueFalseTotal
if $SQL::Translator::Producer::Sybase::WARN 0 0 0
387 "'$name' to make it unique.\n" if $WARN;
388  
389 0 $scope->{ $name_orig }++;
390 }
391 21 ▶ $name = substr( $name, 0, $max_id_length )
Branch: 1 branch
BranchTrueFalseTotal
if length $name > $max_id_length and $critical 0 21 21
Condition33%1/3
length $name > $max_id_length and $critical
!ll&&!rl&&r
2100
MC/DC0%0/2
length $name > $max_id_length and $critical
length $name > $max_id_length $critical
Truth table33%1/3
A and B
A= length $name > $max_id_lengthB= $critical
ABresult
0X0
100
111
392 if ((length( $name ) > $max_id_length) && $critical);
393 21 $scope->{ $name }++;
394 21 return $name;
395 }
396  
397 sub unreserve {
398 24 ▶ my $name = shift || '';
Subroutine unreserve: called CC=7 SCAR=19.5
Pod undocumented
Condition50%1/2
shift() || ''
l!l
240
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
399 24 ▶ my $schema_obj_name = shift || '';
Condition100%2/2
shift() || ''
l!l
204
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
400 24 ▶ my ( $suffix ) = ( $name =~ s/(\W.*)$// ) ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$name =~ s/(\W.*)$// ? : 5 19 24
401  
402 # also trap fields that don't begin with a letter
403 24 ▶ return $name if !$reserved{ uc $name } && $name =~ /^[a-z]/i;
Branch: 1 branch
BranchTrueFalseTotal
if not $reserved{uc $name} and $name =~ /^[a-z]/i 19 5 24
Condition66%2/3
not $reserved{uc $name} and $name =~ /^[a-z]/i
!ll&&!rl&&r
0519
MC/DC50%1/2
not $reserved{uc $name} and $name =~ /^[a-z]/i
not $reserved{uc $name} $name =~ /^[a-z]/i
Truth table66%2/3
not(A) and B
A= not $reserved{uc $name}B= $name =~ /^[a-z]/i
ABresult
0X0
100
111
404  
405 5 ▶ if ( $schema_obj_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema_obj_name) { } 3 2 5
406 3 ++$unreserve{"$schema_obj_name.$name"};
407 }
408 else {
409 2 ++$unreserve{"$name (table name)"};
410 }
411  
412 5 my $unreserve = sprintf '%s_', $name;
413 5 return $unreserve.$suffix;
414 }
415  
416 1 1;
417  
418 =pod
419  
420 =head1 SEE ALSO
421  
422 SQL::Translator.
423  
424 =head1 AUTHORS
425  
426 Sam Angiuoli E<lt>angiuoli@users.sourceforge.netE<gt>,
427 Paul Harrington E<lt>harringp@deshaw.comE<gt>,
428 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.
429  
430 =cut
« blib/lib/SQL/Translator/Producer/MySQL.pm ↑ Summary blib/lib/SQL/Translator/Schema.pm »