line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Dia::SQL::Output::DB2; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: DB2.pm,v 1.5 2009/03/13 14:20:26 aff Exp $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=pod |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Parse::Dia::SQL::Output::DB2 - Create SQL for DB2. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Parse::Dia::SQL; |
14
|
|
|
|
|
|
|
my $dia = Parse::Dia::SQL->new(...); |
15
|
|
|
|
|
|
|
print $dia->get_sql(); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
This class creates SQL for the IBM DB2 database. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
16
|
|
|
16
|
|
17710
|
use warnings; |
|
16
|
|
|
|
|
21
|
|
|
16
|
|
|
|
|
398
|
|
25
|
16
|
|
|
16
|
|
48
|
use strict; |
|
16
|
|
|
|
|
19
|
|
|
16
|
|
|
|
|
223
|
|
26
|
|
|
|
|
|
|
|
27
|
16
|
|
|
16
|
|
41
|
use Data::Dumper; |
|
16
|
|
|
|
|
15
|
|
|
16
|
|
|
|
|
573
|
|
28
|
16
|
|
|
16
|
|
58
|
use File::Spec::Functions qw(catfile); |
|
16
|
|
|
|
|
17
|
|
|
16
|
|
|
|
|
863
|
|
29
|
|
|
|
|
|
|
|
30
|
16
|
|
|
16
|
|
50
|
use lib q{lib}; |
|
16
|
|
|
|
|
209
|
|
|
16
|
|
|
|
|
78
|
|
31
|
16
|
|
|
16
|
|
1091
|
use base q{Parse::Dia::SQL::Output}; # extends |
|
16
|
|
|
|
|
16
|
|
|
16
|
|
|
|
|
1554
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
require Parse::Dia::SQL::Logger; |
34
|
|
|
|
|
|
|
require Parse::Dia::SQL::Const; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 new |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
The constructor. Arguments: |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { |
43
|
|
|
|
|
|
|
my ( $class, %param ) = @_; |
44
|
|
|
|
|
|
|
my $self = {}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Set defaults for db2 |
47
|
|
|
|
|
|
|
$param{object_name_max_length} = $param{object_name_max_length} || 18; |
48
|
|
|
|
|
|
|
$param{index_options} = ['allow reverse scans'] unless |
49
|
|
|
|
|
|
|
defined($param{index_options}) && scalar(@{$param{index_options}}); |
50
|
|
|
|
|
|
|
$param{db} = q{db2}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$self = $class->SUPER::new(%param); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
bless( $self, $class ); |
55
|
|
|
|
|
|
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Create primary key clause, e.g. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
constraint pk_ primary key (,..,) |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
For DB2 the PK must be 18 characters or less |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Returns undefined if list of primary key is empty (i.e. if there are no |
67
|
|
|
|
|
|
|
primary keys on given table). |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _create_pk_string { |
73
|
|
|
|
|
|
|
my ( $self, $tablename, @pks ) = @_; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
if ( !$tablename ) { |
76
|
|
|
|
|
|
|
$self->{log} |
77
|
|
|
|
|
|
|
->error(q{Missing argument tablename - cannot create pk string!}); |
78
|
|
|
|
|
|
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
if ( scalar(@pks) == 0 ) { |
81
|
|
|
|
|
|
|
$self->{log}->debug(qq{table '$tablename' has no primary keys}); |
82
|
|
|
|
|
|
|
return; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# old school name length reduction |
86
|
|
|
|
|
|
|
$tablename = |
87
|
|
|
|
|
|
|
$self->{utils} |
88
|
|
|
|
|
|
|
->mangle_name( $tablename, $self->{object_name_max_length} - 4 ); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# new school name length reduction |
91
|
|
|
|
|
|
|
# $tablename = $self->{utils}->make_name ($tablename); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$self->{log}->debug( qq{tablename: '$tablename' pks: } . join( q{,}, @pks ) ); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
return qq{constraint pk_$tablename primary key (} . join( q{,}, @pks ) . q{)}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
For DB2 a constraint name must be 18 characters or less. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Returns shortened tablename. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _create_constraint_name { |
107
|
|
|
|
|
|
|
my ( $self, $constraint_name ) = @_; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
if ( !defined($constraint_name) || $constraint_name eq q{} ) { |
110
|
|
|
|
|
|
|
$self->{log}->error( qq{constraint_name was undefined or empty!}); |
111
|
|
|
|
|
|
|
return; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# new school |
115
|
|
|
|
|
|
|
return $self->{utils}->make_name (0, $constraint_name); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# old school |
118
|
|
|
|
|
|
|
# return $self->{utils}->mangle_name( $constraint_name, $self->{object_name_max_length} - 4 ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |