line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::Translator::Parser::DBI::Oracle; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
SQL::Translator::Parser::DBI::Oracle - parser for DBD::Oracle |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
See SQL::Translator::Parser::DBI. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Uses DBI introspection methods to determine schema details. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
18
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
19
|
1
|
|
|
1
|
|
1558
|
use DBI; |
|
1
|
|
|
|
|
17448
|
|
|
1
|
|
|
|
|
57
|
|
20
|
1
|
|
|
1
|
|
7
|
use SQL::Translator::Schema::Constants; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
21
|
1
|
|
|
1
|
|
539
|
use SQL::Translator::Schema::Table; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
22
|
1
|
|
|
1
|
|
8
|
use SQL::Translator::Schema::Field; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
23
|
1
|
|
|
1
|
|
5
|
use SQL::Translator::Schema::Constraint; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
492
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = '1.63'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub parse { |
28
|
0
|
|
|
0
|
0
|
|
my ( $tr, $dbh ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $schema = $tr->schema; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $db_user = uc $tr->parser_args()->{db_user}; |
33
|
0
|
|
|
|
|
|
my $sth = $dbh->table_info(undef, $db_user, '%', 'TABLE'); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
while(my $table_info = $sth->fetchrow_hashref('NAME_uc')) { |
36
|
0
|
0
|
|
|
|
|
next if ($table_info->{TABLE_NAME} =~ /\$/); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# create the table |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $table = $schema->add_table( |
41
|
|
|
|
|
|
|
name => $table_info->{TABLE_NAME}, |
42
|
|
|
|
|
|
|
type => $table_info->{TABLE_TYPE}, |
43
|
0
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# add the fields (columns) for this table |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $sth; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$sth = $dbh->column_info( |
50
|
|
|
|
|
|
|
undef, |
51
|
|
|
|
|
|
|
$table_info->{TABLE_SCHEM}, |
52
|
|
|
|
|
|
|
$table_info->{TABLE_NAME}, |
53
|
0
|
|
|
|
|
|
'%' |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
while(my $column = $sth->fetchrow_hashref('NAME_uc')) { |
57
|
|
|
|
|
|
|
my $f = $table->add_field( |
58
|
|
|
|
|
|
|
name => $column->{COLUMN_NAME}, |
59
|
|
|
|
|
|
|
default_value => $column->{COLUMN_DEF}, |
60
|
|
|
|
|
|
|
data_type => $column->{TYPE_NAME}, |
61
|
|
|
|
|
|
|
order => $column->{ORDINAL_POSITION}, |
62
|
|
|
|
|
|
|
size => $column->{COLUMN_SIZE}, |
63
|
0
|
|
0
|
|
|
|
) || die $table->error; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$f->is_nullable( $column->{NULLABLE} == 1 ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# add the primary key info |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$sth = $dbh->primary_key_info( |
71
|
|
|
|
|
|
|
undef, |
72
|
|
|
|
|
|
|
$table_info->{TABLE_SCHEM}, |
73
|
|
|
|
|
|
|
$table_info->{TABLE_NAME}, |
74
|
0
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
while(my $primary_key = $sth->fetchrow_hashref('NAME_uc')) { |
77
|
0
|
|
|
|
|
|
my $f = $table->get_field( $primary_key->{COLUMN_NAME} ); |
78
|
0
|
|
|
|
|
|
$f->is_primary_key(1); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# add the foreign key info (constraints) |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$sth = $dbh->foreign_key_info( |
84
|
|
|
|
|
|
|
undef, |
85
|
|
|
|
|
|
|
undef, |
86
|
|
|
|
|
|
|
undef, |
87
|
|
|
|
|
|
|
undef, |
88
|
|
|
|
|
|
|
$table_info->{TABLE_SCHEM}, |
89
|
|
|
|
|
|
|
$table_info->{TABLE_NAME}, |
90
|
0
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $cons = {}; |
93
|
0
|
|
|
|
|
|
while(my $foreign_key = $sth->fetchrow_hashref('NAME_uc')) { |
94
|
0
|
|
|
|
|
|
my $name = $foreign_key->{FK_NAME}; |
95
|
0
|
|
|
|
|
|
$cons->{$name}->{reference_table} = $foreign_key->{UK_TABLE_NAME}; |
96
|
0
|
|
|
|
|
|
push @{ $cons->{$name}->{fields} }, |
97
|
0
|
|
|
|
|
|
$foreign_key->{FK_COLUMN_NAME}; |
98
|
0
|
|
|
|
|
|
push @{ $cons->{$name}->{reference_fields} }, |
99
|
0
|
|
|
|
|
|
$foreign_key->{UK_COLUMN_NAME}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
for my $name ( keys %$cons ) { |
103
|
|
|
|
|
|
|
my $c = $table->add_constraint( |
104
|
|
|
|
|
|
|
type => FOREIGN_KEY, |
105
|
|
|
|
|
|
|
name => $name, |
106
|
|
|
|
|
|
|
fields => $cons->{$name}->{fields}, |
107
|
|
|
|
|
|
|
reference_fields => $cons->{$name}->{reference_fields}, |
108
|
|
|
|
|
|
|
reference_table => $cons->{$name}->{reference_table}, |
109
|
0
|
|
0
|
|
|
|
) || die $table->error; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return 1; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=pod |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 AUTHOR |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Earl Cahill Ecpan@spack.netE. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENT |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Initial revision of this module came almost entirely from work done by |
127
|
|
|
|
|
|
|
Todd Hepler Ethepler@freeshell.orgE. My changes were |
128
|
|
|
|
|
|
|
quite minor (ensuring NAME_uc, changing a couple variable names, |
129
|
|
|
|
|
|
|
skipping tables with a $ in them). |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Todd claimed his work to be an almost verbatim copy of |
132
|
|
|
|
|
|
|
SQL::Translator::Parser::DBI::PostgreSQL revision 1.7 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
For me, the real work happens in DBD::Oracle and DBI, which, also |
135
|
|
|
|
|
|
|
for me, that is the beauty of having introspection methods in DBI. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SEE ALSO |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
SQL::Translator, DBD::Oracle. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |