line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::Schema::Loader::DBI; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
12194
|
use strict; |
|
17
|
|
|
|
|
42
|
|
|
17
|
|
|
|
|
575
|
|
4
|
17
|
|
|
17
|
|
115
|
use warnings; |
|
17
|
|
|
|
|
56
|
|
|
17
|
|
|
|
|
531
|
|
5
|
17
|
|
|
17
|
|
104
|
use base qw/DBIx::Class::Schema::Loader::Base/; |
|
17
|
|
|
|
|
40
|
|
|
17
|
|
|
|
|
2995
|
|
6
|
17
|
|
|
17
|
|
144
|
use mro 'c3'; |
|
17
|
|
|
|
|
36
|
|
|
17
|
|
|
|
|
133
|
|
7
|
17
|
|
|
17
|
|
537
|
use Try::Tiny; |
|
17
|
|
|
|
|
80
|
|
|
17
|
|
|
|
|
1214
|
|
8
|
17
|
|
|
17
|
|
446
|
use List::Util 'any'; |
|
17
|
|
|
|
|
42
|
|
|
17
|
|
|
|
|
1273
|
|
9
|
17
|
|
|
17
|
|
145
|
use Carp::Clan qw/^DBIx::Class/; |
|
17
|
|
|
|
|
36
|
|
|
17
|
|
|
|
|
196
|
|
10
|
17
|
|
|
17
|
|
2328
|
use namespace::clean; |
|
17
|
|
|
|
|
40
|
|
|
17
|
|
|
|
|
148
|
|
11
|
17
|
|
|
17
|
|
13941
|
use DBIx::Class::Schema::Loader::Table (); |
|
17
|
|
|
|
|
52
|
|
|
17
|
|
|
|
|
72292
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.07051'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
__PACKAGE__->mk_group_accessors('simple', qw/ |
16
|
|
|
|
|
|
|
_disable_pk_detection |
17
|
|
|
|
|
|
|
_disable_uniq_detection |
18
|
|
|
|
|
|
|
_disable_fk_detection |
19
|
|
|
|
|
|
|
_passwords |
20
|
|
|
|
|
|
|
quote_char |
21
|
|
|
|
|
|
|
name_sep |
22
|
|
|
|
|
|
|
/); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
DBIx::Class::Schema::Loader::DBI - DBIx::Class::Schema::Loader DBI Implementation. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
See L |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This is the base class for L classes for |
35
|
|
|
|
|
|
|
DBI-based storage backends, and implements the common functionality between them. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
See L for the available options. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 METHODS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 new |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Overlays L to do some DBI-specific |
44
|
|
|
|
|
|
|
things. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
116
|
|
|
116
|
1
|
835
|
my $self = shift->next::method(@_); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# rebless to vendor-specific class if it exists and loads and we're not in a |
52
|
|
|
|
|
|
|
# custom class. |
53
|
116
|
100
|
|
|
|
828
|
if (not $self->loader_class) { |
54
|
107
|
|
|
|
|
4761
|
my $driver = $self->dbh->{Driver}->{Name}; |
55
|
|
|
|
|
|
|
|
56
|
107
|
|
|
|
|
217919
|
my $subclass = 'DBIx::Class::Schema::Loader::DBI::' . $driver; |
57
|
107
|
50
|
33
|
|
|
2337
|
if ((not $self->isa($subclass)) && $self->load_optional_class($subclass)) { |
58
|
107
|
|
|
|
|
2475
|
bless $self, $subclass; |
59
|
107
|
|
|
|
|
1200
|
$self->_rebless; |
60
|
107
|
50
|
|
|
|
986
|
Class::C3::reinitialize() if $] < 5.009005; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Set up the default quoting character and name separators |
65
|
116
|
|
|
|
|
1448
|
$self->quote_char($self->_build_quote_char); |
66
|
116
|
|
|
|
|
5208
|
$self->name_sep($self->_build_name_sep); |
67
|
|
|
|
|
|
|
|
68
|
116
|
|
|
|
|
41086
|
$self->_setup; |
69
|
|
|
|
|
|
|
|
70
|
116
|
|
|
|
|
1472
|
return $self; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _build_quote_char { |
74
|
116
|
|
|
116
|
|
330
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
116
|
|
50
|
|
|
547
|
my $quote_char = $self->dbh->get_info(29) |
77
|
|
|
|
|
|
|
|| $self->schema->storage->sql_maker->quote_char |
78
|
|
|
|
|
|
|
|| q{"}; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# For our usage as regex matches, concatenating multiple quote_char |
81
|
|
|
|
|
|
|
# values works fine (e.g. s/[\Q<>\E]// if quote_char was [ '<', '>' ]) |
82
|
116
|
50
|
|
|
|
104649
|
if (ref $quote_char eq 'ARRAY') { |
83
|
0
|
|
|
|
|
0
|
$quote_char = join '', @$quote_char; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
116
|
|
|
|
|
910
|
return $quote_char; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _build_name_sep { |
90
|
116
|
|
|
116
|
|
364
|
my $self = shift; |
91
|
116
|
|
50
|
|
|
382
|
return $self->dbh->get_info(41) |
92
|
|
|
|
|
|
|
|| $self->schema->storage->sql_maker->name_sep |
93
|
|
|
|
|
|
|
|| '.'; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Override this in vendor modules to do things at the end of ->new() |
97
|
|
|
|
118
|
|
|
sub _setup { } |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Override this in vendor module to load a subclass if necessary |
100
|
|
|
|
107
|
|
|
sub _rebless { } |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _system_schemas { |
103
|
12
|
|
|
12
|
|
29
|
return ('information_schema'); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _system_tables { |
107
|
12
|
|
|
12
|
|
29
|
return (); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _dbh_tables { |
111
|
3
|
|
|
3
|
|
9
|
my $self = shift; |
112
|
|
|
|
|
|
|
|
113
|
3
|
|
|
|
|
10
|
return $self->dbh->tables(undef, @_); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# default to be overridden in subclasses if necessary |
117
|
12
|
|
|
12
|
|
62
|
sub _supports_db_schema { 1 } |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Returns an array of table objects |
120
|
|
|
|
|
|
|
sub _tables_list { |
121
|
3
|
|
|
3
|
|
12
|
my ($self) = @_; |
122
|
|
|
|
|
|
|
|
123
|
3
|
|
|
|
|
8
|
my @tables; |
124
|
|
|
|
|
|
|
|
125
|
3
|
|
|
|
|
49
|
my $qt = qr/[\Q$self->{quote_char}\E"'`\[\]]/; |
126
|
3
|
|
|
|
|
25
|
my $nqt = qr/[^\Q$self->{quote_char}\E"'`\[\]]/; |
127
|
3
|
|
|
|
|
25
|
my $ns = qr/[\Q$self->{name_sep}\E]/; |
128
|
3
|
|
|
|
|
21
|
my $nns = qr/[^\Q$self->{name_sep}\E]/; |
129
|
|
|
|
|
|
|
|
130
|
3
|
50
|
|
|
|
9
|
foreach my $schema (@{ $self->db_schema || [undef] }) { |
|
3
|
|
|
|
|
28
|
|
131
|
3
|
|
|
|
|
18
|
my @raw_table_names = $self->_dbh_tables($schema); |
132
|
|
|
|
|
|
|
|
133
|
3
|
|
|
|
|
2675
|
TABLE: foreach my $raw_table_name (@raw_table_names) { |
134
|
12
|
|
|
|
|
74
|
my $quoted = $raw_table_name =~ /^$qt/; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# These regexes are not entirely correct, but hopefully they will work |
137
|
|
|
|
|
|
|
# in most cases. RT reports welcome. |
138
|
12
|
50
|
|
|
|
176
|
my ($schema_name, $table_name1, $table_name2) = $quoted ? |
139
|
|
|
|
|
|
|
$raw_table_name =~ /^(?:${qt}(${nqt}+?)${qt}${ns})?(?:${qt}(.+?)${qt}|(${nns}+))\z/ |
140
|
|
|
|
|
|
|
: |
141
|
|
|
|
|
|
|
$raw_table_name =~ /^(?:(${nns}+?)${ns})?(?:${qt}(.+?)${qt}|(${nns}+))\z/; |
142
|
|
|
|
|
|
|
|
143
|
12
|
|
33
|
|
|
44
|
my $table_name = $table_name1 || $table_name2; |
144
|
|
|
|
|
|
|
|
145
|
12
|
|
|
|
|
40
|
foreach my $system_schema ($self->_system_schemas) { |
146
|
12
|
50
|
|
|
|
29
|
if ($schema_name) { |
147
|
12
|
|
|
|
|
23
|
my $matches = 0; |
148
|
|
|
|
|
|
|
|
149
|
12
|
50
|
|
|
|
30
|
if (ref $system_schema) { |
150
|
0
|
0
|
0
|
|
|
0
|
$matches = 1 |
151
|
|
|
|
|
|
|
if $schema_name =~ $system_schema |
152
|
|
|
|
|
|
|
&& $schema !~ $system_schema; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
else { |
155
|
12
|
50
|
33
|
|
|
36
|
$matches = 1 |
156
|
|
|
|
|
|
|
if $schema_name eq $system_schema |
157
|
|
|
|
|
|
|
&& $schema ne $system_schema; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
12
|
50
|
|
|
|
32
|
next TABLE if $matches; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
12
|
|
|
|
|
30
|
foreach my $system_table ($self->_system_tables) { |
165
|
0
|
|
|
|
|
0
|
my $matches = 0; |
166
|
|
|
|
|
|
|
|
167
|
0
|
0
|
|
|
|
0
|
if (ref $system_table) { |
168
|
0
|
0
|
|
|
|
0
|
$matches = 1 if $table_name =~ $system_table; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else { |
171
|
0
|
0
|
|
|
|
0
|
$matches = 1 if $table_name eq $system_table |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
0
|
0
|
|
|
|
0
|
next TABLE if $matches; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
12
|
|
33
|
|
|
27
|
$schema_name ||= $schema; |
178
|
|
|
|
|
|
|
|
179
|
12
|
50
|
|
|
|
35
|
my $table = DBIx::Class::Schema::Loader::Table->new( |
180
|
|
|
|
|
|
|
loader => $self, |
181
|
|
|
|
|
|
|
name => $table_name, |
182
|
|
|
|
|
|
|
schema => $schema_name, |
183
|
|
|
|
|
|
|
($self->_supports_db_schema ? () : ( |
184
|
|
|
|
|
|
|
ignore_schema => 1 |
185
|
|
|
|
|
|
|
)), |
186
|
|
|
|
|
|
|
); |
187
|
|
|
|
|
|
|
|
188
|
12
|
|
|
|
|
41
|
push @tables, $table; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
3
|
|
|
|
|
28
|
return $self->_filter_tables(\@tables); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub _recurse_constraint { |
196
|
8
|
|
|
8
|
|
31
|
my ($constraint, @parts) = @_; |
197
|
|
|
|
|
|
|
|
198
|
8
|
|
|
|
|
28
|
my $name = shift @parts; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# If there are any parts left, the constraint must be an arrayref |
201
|
8
|
50
|
|
|
|
54
|
croak "depth of constraint/exclude array does not match length of moniker_parts" |
202
|
|
|
|
|
|
|
unless !!@parts == !!(ref $constraint eq 'ARRAY'); |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# if ths is the last part, use the constraint directly |
205
|
8
|
100
|
|
|
|
115
|
return $name =~ $constraint unless @parts; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
# recurse into the first matching subconstraint |
208
|
4
|
|
|
|
|
19
|
foreach (@{$constraint}) { |
|
4
|
|
|
|
|
25
|
|
209
|
4
|
|
|
|
|
26
|
my ($re, $sub) = @{$_}; |
|
4
|
|
|
|
|
14
|
|
210
|
4
|
50
|
|
|
|
79
|
return _recurse_constraint($sub, @parts) |
211
|
|
|
|
|
|
|
if $name =~ $re; |
212
|
|
|
|
|
|
|
} |
213
|
0
|
|
|
|
|
0
|
return 0; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub _check_constraint { |
217
|
242
|
|
|
242
|
|
8492
|
my ($include, $constraint, @tables) = @_; |
218
|
|
|
|
|
|
|
|
219
|
242
|
100
|
|
|
|
1049
|
return @tables unless defined $constraint; |
220
|
|
|
|
|
|
|
|
221
|
9
|
100
|
75
|
|
|
72
|
return grep { !$include xor _recurse_constraint($constraint, @{$_}) } @tables |
|
4
|
|
|
|
|
19
|
|
|
4
|
|
|
|
|
88
|
|
222
|
|
|
|
|
|
|
if ref $constraint eq 'ARRAY'; |
223
|
|
|
|
|
|
|
|
224
|
7
|
|
25
|
|
|
28
|
return grep { !$include xor /$constraint/ } @tables; |
|
364
|
|
|
|
|
1773
|
|
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# apply constraint/exclude and ignore bad tables and views |
230
|
|
|
|
|
|
|
sub _filter_tables { |
231
|
121
|
|
|
121
|
|
503
|
my ($self, $tables) = @_; |
232
|
|
|
|
|
|
|
|
233
|
121
|
|
|
|
|
551
|
my @tables = @$tables; |
234
|
121
|
|
|
|
|
289
|
my @filtered_tables; |
235
|
|
|
|
|
|
|
|
236
|
121
|
|
|
|
|
963
|
@tables = _check_constraint(1, $self->constraint, @tables); |
237
|
121
|
|
|
|
|
760
|
@tables = _check_constraint(0, $self->exclude, @tables); |
238
|
|
|
|
|
|
|
|
239
|
121
|
|
|
|
|
596
|
TABLE: for my $table (@tables) { |
240
|
|
|
|
|
|
|
try { |
241
|
781
|
|
|
781
|
|
56411
|
local $^W = 0; # for ADO |
242
|
781
|
|
|
|
|
2880
|
my $sth = $self->_sth_for($table, undef, \'1 = 0'); |
243
|
781
|
|
|
|
|
39503
|
$sth->execute; |
244
|
781
|
|
|
|
|
15269
|
1; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
catch { |
247
|
0
|
|
|
0
|
|
0
|
warn "Bad table or view '$table', ignoring: $_\n"; |
248
|
0
|
|
|
|
|
0
|
0; |
249
|
781
|
50
|
|
|
|
6140
|
} or next TABLE; |
250
|
|
|
|
|
|
|
|
251
|
781
|
|
|
|
|
16192
|
push @filtered_tables, $table; |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
121
|
|
|
|
|
3118
|
return @filtered_tables; |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head2 load |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
We override L here to hook in our localized settings for C<$dbh> error handling. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=cut |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub load { |
264
|
116
|
|
|
116
|
1
|
2921
|
my $self = shift; |
265
|
|
|
|
|
|
|
|
266
|
116
|
|
|
|
|
419
|
local $self->dbh->{RaiseError} = 1; |
267
|
116
|
|
|
|
|
33068
|
local $self->dbh->{PrintError} = 0; |
268
|
|
|
|
|
|
|
|
269
|
116
|
|
|
|
|
33068
|
$self->next::method(@_); |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
sub _sth_for { |
273
|
2337
|
|
|
2337
|
|
5663
|
my ($self, $table, $fields, $where) = @_; |
274
|
|
|
|
|
|
|
|
275
|
2337
|
|
50
|
|
|
6030
|
my $sth = $self->dbh->prepare($self->schema->storage->sql_maker |
276
|
|
|
|
|
|
|
->select(\$table->sql_name, $fields || \'*', $where)); |
277
|
|
|
|
|
|
|
|
278
|
2337
|
|
|
|
|
722901
|
return $sth; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
# Returns an arrayref of column names |
282
|
|
|
|
|
|
|
sub _table_columns { |
283
|
778
|
|
|
778
|
|
2284
|
my ($self, $table) = @_; |
284
|
|
|
|
|
|
|
|
285
|
778
|
|
|
|
|
2984
|
my $sth = $self->_sth_for($table, undef, \'1 = 0'); |
286
|
778
|
|
|
|
|
40797
|
$sth->execute; |
287
|
|
|
|
|
|
|
|
288
|
778
|
|
|
|
|
3724
|
my $retval = [ map $self->_lc($_), @{$sth->{NAME}} ]; |
|
778
|
|
|
|
|
12505
|
|
289
|
|
|
|
|
|
|
|
290
|
778
|
|
|
|
|
5518
|
$sth->finish; |
291
|
|
|
|
|
|
|
|
292
|
778
|
|
|
|
|
10102
|
return $retval; |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
# Returns arrayref of pk col names |
296
|
|
|
|
|
|
|
sub _table_pk_info { |
297
|
778
|
|
|
778
|
|
2776
|
my ($self, $table) = @_; |
298
|
|
|
|
|
|
|
|
299
|
778
|
50
|
|
|
|
3972
|
return [] if $self->_disable_pk_detection; |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
my @primary = try { |
302
|
778
|
|
|
778
|
|
59651
|
$self->dbh->primary_key('', $table->schema, $table->name); |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
catch { |
305
|
0
|
|
|
0
|
|
0
|
warn "Cannot find primary keys for this driver: $_"; |
306
|
0
|
|
|
|
|
0
|
$self->_disable_pk_detection(1); |
307
|
0
|
|
|
|
|
0
|
return (); |
308
|
778
|
|
|
|
|
13102
|
}; |
309
|
|
|
|
|
|
|
|
310
|
778
|
100
|
|
|
|
1163325
|
return [] if not @primary; |
311
|
|
|
|
|
|
|
|
312
|
751
|
|
|
|
|
2808
|
@primary = map { $self->_lc($_) } @primary; |
|
846
|
|
|
|
|
3799
|
|
313
|
751
|
|
|
|
|
6855
|
s/[\Q$self->{quote_char}\E]//g for @primary; |
314
|
|
|
|
|
|
|
|
315
|
751
|
|
|
|
|
4440
|
return \@primary; |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
# Override this for vendor-specific uniq info |
319
|
|
|
|
|
|
|
sub _table_uniq_info { |
320
|
24
|
|
|
24
|
|
65
|
my ($self, $table) = @_; |
321
|
|
|
|
|
|
|
|
322
|
24
|
50
|
|
|
|
112
|
return [] if $self->_disable_uniq_detection; |
323
|
|
|
|
|
|
|
|
324
|
24
|
50
|
|
|
|
270
|
if (not $self->dbh->can('statistics_info')) { |
325
|
0
|
|
|
|
|
0
|
warn "No UNIQUE constraint information can be gathered for this driver"; |
326
|
0
|
|
|
|
|
0
|
$self->_disable_uniq_detection(1); |
327
|
0
|
|
|
|
|
0
|
return []; |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
|
330
|
24
|
|
|
|
|
6399
|
my %indices; |
331
|
24
|
|
|
|
|
80
|
my $sth = $self->dbh->statistics_info(undef, $table->schema, $table->name, 1, 1); |
332
|
24
|
|
|
|
|
18267
|
while(my $row = $sth->fetchrow_hashref) { |
333
|
|
|
|
|
|
|
# skip table-level stats, conditional indexes, and any index missing |
334
|
|
|
|
|
|
|
# critical fields |
335
|
|
|
|
|
|
|
next if $row->{TYPE} eq 'table' |
336
|
|
|
|
|
|
|
|| defined $row->{FILTER_CONDITION} |
337
|
|
|
|
|
|
|
|| !$row->{INDEX_NAME} |
338
|
0
|
0
|
0
|
|
|
0
|
|| !defined $row->{ORDINAL_POSITION}; |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
339
|
|
|
|
|
|
|
|
340
|
0
|
|
0
|
|
|
0
|
$indices{$row->{INDEX_NAME}}[$row->{ORDINAL_POSITION}] = $self->_lc($row->{COLUMN_NAME} || ''); |
341
|
|
|
|
|
|
|
} |
342
|
24
|
|
|
|
|
601
|
$sth->finish; |
343
|
|
|
|
|
|
|
|
344
|
24
|
|
|
|
|
56
|
my @retval; |
345
|
24
|
|
|
|
|
115
|
foreach my $index_name (sort keys %indices) { |
346
|
0
|
|
|
|
|
0
|
my (undef, @cols) = @{$indices{$index_name}}; |
|
0
|
|
|
|
|
0
|
|
347
|
|
|
|
|
|
|
# skip indexes with missing column names (e.g. expression indexes) |
348
|
0
|
0
|
|
|
|
0
|
next unless @cols == grep $_, @cols; |
349
|
0
|
|
|
|
|
0
|
push(@retval, [ $index_name => \@cols ]); |
350
|
|
|
|
|
|
|
} |
351
|
|
|
|
|
|
|
|
352
|
24
|
|
|
|
|
783
|
return \@retval; |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
sub _table_comment { |
356
|
1540
|
|
|
1540
|
|
3702
|
my ($self, $table) = @_; |
357
|
1540
|
|
|
|
|
4545
|
my $dbh = $self->dbh; |
358
|
|
|
|
|
|
|
|
359
|
1540
|
|
|
|
|
455329
|
my $comments_table = $table->clone; |
360
|
1540
|
|
|
|
|
6939
|
$comments_table->name($self->table_comments_table); |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
my ($comment) = |
363
|
|
|
|
|
|
|
(exists $self->_tables->{$comments_table->sql_name} || undef) |
364
|
1540
|
|
66
|
16
|
|
10908
|
&& try { $dbh->selectrow_array(<<"EOF") }; |
|
16
|
|
|
|
|
663
|
|
365
|
|
|
|
|
|
|
SELECT comment_text |
366
|
16
|
|
|
|
|
57
|
FROM @{[ $comments_table->sql_name ]} |
367
|
16
|
|
|
|
|
99
|
WHERE table_name = @{[ $dbh->quote($table->name) ]} |
368
|
|
|
|
|
|
|
EOF |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
# Failback: try the REMARKS column on table_info |
371
|
1540
|
100
|
|
|
|
19204
|
if (!$comment) { |
372
|
1536
|
|
|
|
|
4708
|
my $info = $self->_dbh_table_info( $dbh, $table ); |
373
|
1536
|
50
|
|
|
|
34154
|
$comment = $info->{REMARKS} if $info; |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
|
376
|
1540
|
|
|
|
|
9876
|
return $comment; |
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
sub _column_comment { |
380
|
2196
|
|
|
2196
|
|
6283
|
my ($self, $table, $column_number, $column_name) = @_; |
381
|
2196
|
|
|
|
|
6336
|
my $dbh = $self->dbh; |
382
|
|
|
|
|
|
|
|
383
|
2196
|
|
|
|
|
611366
|
my $comments_table = $table->clone; |
384
|
2196
|
|
|
|
|
9122
|
$comments_table->name($self->column_comments_table); |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
my ($comment) = |
387
|
|
|
|
|
|
|
(exists $self->_tables->{$comments_table->sql_name} || undef) |
388
|
2196
|
|
66
|
19
|
|
13090
|
&& try { $dbh->selectrow_array(<<"EOF") }; |
|
19
|
|
|
|
|
802
|
|
389
|
|
|
|
|
|
|
SELECT comment_text |
390
|
19
|
|
|
|
|
61
|
FROM @{[ $comments_table->sql_name ]} |
391
|
19
|
|
|
|
|
126
|
WHERE table_name = @{[ $dbh->quote($table->name) ]} |
392
|
19
|
|
|
|
|
289
|
AND column_name = @{[ $dbh->quote($column_name) ]} |
393
|
|
|
|
|
|
|
EOF |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
# Failback: try the REMARKS column on column_info |
396
|
2196
|
100
|
66
|
|
|
32148
|
if (!$comment && $dbh->can('column_info')) { |
397
|
2194
|
50
|
|
2194
|
|
15650
|
if (my $sth = try { $self->_dbh_column_info( $dbh, undef, $table->schema, $table->name, $column_name ) }) { |
|
2194
|
|
|
|
|
98305
|
|
398
|
2194
|
|
|
|
|
2949057
|
my $info = $sth->fetchrow_hashref(); |
399
|
2194
|
|
|
|
|
68258
|
$comment = $info->{REMARKS}; |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
} |
402
|
|
|
|
|
|
|
|
403
|
2196
|
|
|
|
|
89737
|
return $comment; |
404
|
|
|
|
|
|
|
} |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
# Find relationships |
407
|
|
|
|
|
|
|
sub _table_fk_info { |
408
|
24
|
|
|
24
|
|
105
|
my ($self, $table) = @_; |
409
|
|
|
|
|
|
|
|
410
|
24
|
50
|
|
|
|
109
|
return [] if $self->_disable_fk_detection; |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
my $sth = try { |
413
|
24
|
|
50
|
24
|
|
1171
|
$self->dbh->foreign_key_info( '', '', '', |
414
|
|
|
|
|
|
|
'', ($table->schema || ''), $table->name ); |
415
|
|
|
|
|
|
|
} |
416
|
|
|
|
|
|
|
catch { |
417
|
0
|
|
|
0
|
|
0
|
warn "Cannot introspect relationships for this driver: $_"; |
418
|
0
|
|
|
|
|
0
|
$self->_disable_fk_detection(1); |
419
|
0
|
|
|
|
|
0
|
return undef; |
420
|
24
|
|
|
|
|
427
|
}; |
421
|
|
|
|
|
|
|
|
422
|
24
|
50
|
|
|
|
20258
|
return [] if !$sth; |
423
|
|
|
|
|
|
|
|
424
|
24
|
|
|
|
|
69
|
my %rels; |
425
|
|
|
|
|
|
|
|
426
|
24
|
|
|
|
|
94
|
my @rules = ( |
427
|
|
|
|
|
|
|
'CASCADE', |
428
|
|
|
|
|
|
|
'RESTRICT', |
429
|
|
|
|
|
|
|
'SET NULL', |
430
|
|
|
|
|
|
|
'NO ACTION', |
431
|
|
|
|
|
|
|
'SET DEFAULT', |
432
|
|
|
|
|
|
|
); |
433
|
|
|
|
|
|
|
|
434
|
24
|
|
|
|
|
52
|
my $i = 1; # for unnamed rels, which hopefully have only 1 column ... |
435
|
24
|
|
|
|
|
132
|
REL: while(my $raw_rel = $sth->fetchrow_arrayref) { |
436
|
0
|
|
|
|
|
0
|
my $uk_scm = $raw_rel->[1]; |
437
|
0
|
|
|
|
|
0
|
my $uk_tbl = $raw_rel->[2]; |
438
|
0
|
|
|
|
|
0
|
my $uk_col = $self->_lc($raw_rel->[3]); |
439
|
0
|
|
|
|
|
0
|
my $fk_scm = $raw_rel->[5]; |
440
|
0
|
|
|
|
|
0
|
my $fk_col = $self->_lc($raw_rel->[7]); |
441
|
0
|
|
|
|
|
0
|
my $key_seq = $raw_rel->[8] - 1; |
442
|
0
|
|
0
|
|
|
0
|
my $relid = ($raw_rel->[11] || ( "__dcsld__" . $i++ )); |
443
|
|
|
|
|
|
|
|
444
|
0
|
|
|
|
|
0
|
my $update_rule = $raw_rel->[9]; |
445
|
0
|
|
|
|
|
0
|
my $delete_rule = $raw_rel->[10]; |
446
|
|
|
|
|
|
|
|
447
|
0
|
0
|
|
|
|
0
|
$update_rule = $rules[$update_rule] if defined $update_rule; |
448
|
0
|
0
|
|
|
|
0
|
$delete_rule = $rules[$delete_rule] if defined $delete_rule; |
449
|
|
|
|
|
|
|
|
450
|
0
|
|
|
|
|
0
|
my $is_deferrable = $raw_rel->[13]; |
451
|
|
|
|
|
|
|
|
452
|
0
|
0
|
|
|
|
0
|
($is_deferrable = $is_deferrable == 7 ? 0 : 1) |
|
|
0
|
|
|
|
|
|
453
|
|
|
|
|
|
|
if defined $is_deferrable; |
454
|
|
|
|
|
|
|
|
455
|
0
|
|
|
|
|
0
|
foreach my $var ($uk_scm, $uk_tbl, $uk_col, $fk_scm, $fk_col, $relid) { |
456
|
0
|
0
|
|
|
|
0
|
$var =~ s/[\Q$self->{quote_char}\E]//g if defined $var; |
457
|
|
|
|
|
|
|
} |
458
|
|
|
|
|
|
|
|
459
|
0
|
0
|
0
|
|
|
0
|
if ($self->db_schema && $self->db_schema->[0] ne '%' |
|
|
|
0
|
|
|
|
|
460
|
0
|
|
|
0
|
|
0
|
&& (not any { $_ eq $uk_scm } @{ $self->db_schema })) { |
|
0
|
|
|
|
|
0
|
|
461
|
|
|
|
|
|
|
|
462
|
0
|
|
|
|
|
0
|
next REL; |
463
|
|
|
|
|
|
|
} |
464
|
|
|
|
|
|
|
|
465
|
0
|
0
|
0
|
|
|
0
|
$rels{$relid}{tbl} ||= DBIx::Class::Schema::Loader::Table->new( |
466
|
|
|
|
|
|
|
loader => $self, |
467
|
|
|
|
|
|
|
name => $uk_tbl, |
468
|
|
|
|
|
|
|
schema => $uk_scm, |
469
|
|
|
|
|
|
|
($self->_supports_db_schema ? () : ( |
470
|
|
|
|
|
|
|
ignore_schema => 1 |
471
|
|
|
|
|
|
|
)), |
472
|
|
|
|
|
|
|
); |
473
|
|
|
|
|
|
|
|
474
|
0
|
0
|
|
|
|
0
|
$rels{$relid}{attrs}{on_delete} = $delete_rule if $delete_rule; |
475
|
0
|
0
|
|
|
|
0
|
$rels{$relid}{attrs}{on_update} = $update_rule if $update_rule; |
476
|
0
|
0
|
|
|
|
0
|
$rels{$relid}{attrs}{is_deferrable} = $is_deferrable if defined $is_deferrable; |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
# Add this data IN ORDER |
479
|
0
|
|
|
|
|
0
|
$rels{$relid}{rcols}[$key_seq] = $uk_col; |
480
|
0
|
|
|
|
|
0
|
$rels{$relid}{lcols}[$key_seq] = $fk_col; |
481
|
|
|
|
|
|
|
} |
482
|
24
|
|
|
|
|
543
|
$sth->finish; |
483
|
|
|
|
|
|
|
|
484
|
24
|
|
|
|
|
51
|
my @rels; |
485
|
24
|
|
|
|
|
89
|
foreach my $relid (keys %rels) { |
486
|
|
|
|
|
|
|
push(@rels, { |
487
|
0
|
|
|
|
|
0
|
remote_columns => [ grep defined, @{ $rels{$relid}{rcols} } ], |
488
|
0
|
|
|
|
|
0
|
local_columns => [ grep defined, @{ $rels{$relid}{lcols} } ], |
489
|
|
|
|
|
|
|
remote_table => $rels{$relid}->{tbl}, |
490
|
|
|
|
|
|
|
(exists $rels{$relid}{attrs} ? |
491
|
|
|
|
|
|
|
(attrs => $rels{$relid}{attrs}) |
492
|
0
|
0
|
|
|
|
0
|
: |
493
|
|
|
|
|
|
|
() |
494
|
|
|
|
|
|
|
), |
495
|
|
|
|
|
|
|
_constraint_name => $relid, |
496
|
|
|
|
|
|
|
}); |
497
|
|
|
|
|
|
|
} |
498
|
|
|
|
|
|
|
|
499
|
24
|
|
|
|
|
861
|
return \@rels; |
500
|
|
|
|
|
|
|
} |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
# ported in from DBIx::Class::Storage::DBI: |
503
|
|
|
|
|
|
|
sub _columns_info_for { |
504
|
778
|
|
|
778
|
|
9241
|
my ($self, $table) = @_; |
505
|
|
|
|
|
|
|
|
506
|
778
|
|
|
|
|
23635
|
my $dbh = $self->schema->storage->dbh; |
507
|
|
|
|
|
|
|
|
508
|
778
|
|
|
|
|
213972
|
my %result; |
509
|
|
|
|
|
|
|
my %raw_result; |
510
|
|
|
|
|
|
|
|
511
|
778
|
50
|
|
778
|
|
5887
|
if (my $sth = try { $self->_dbh_column_info($dbh, undef, $table->schema, $table->name, '%' ) }) { |
|
778
|
|
|
|
|
35800
|
|
512
|
778
|
|
|
1286
|
|
826173
|
COL_INFO: while (my $info = try { $sth->fetchrow_hashref } catch { +{} }) { |
|
2979
|
|
|
|
|
233758
|
|
|
0
|
|
|
|
|
0
|
|
513
|
2201
|
50
|
|
|
|
88636
|
next COL_INFO unless %$info; |
514
|
|
|
|
|
|
|
|
515
|
2201
|
|
|
|
|
5150
|
my $column_info = {}; |
516
|
2201
|
|
|
|
|
7974
|
$column_info->{data_type} = lc $info->{TYPE_NAME}; |
517
|
|
|
|
|
|
|
|
518
|
2201
|
|
|
|
|
4963
|
my $size = $info->{COLUMN_SIZE}; |
519
|
|
|
|
|
|
|
|
520
|
2201
|
100
|
100
|
|
|
10451
|
if (defined $size && defined $info->{DECIMAL_DIGITS}) { |
|
|
100
|
|
|
|
|
|
521
|
21
|
|
|
|
|
82
|
$column_info->{size} = [$size, $info->{DECIMAL_DIGITS}]; |
522
|
|
|
|
|
|
|
} |
523
|
|
|
|
|
|
|
elsif (defined $size) { |
524
|
262
|
|
|
|
|
836
|
$column_info->{size} = $size; |
525
|
|
|
|
|
|
|
} |
526
|
|
|
|
|
|
|
|
527
|
2201
|
100
|
|
|
|
7359
|
$column_info->{is_nullable} = $info->{NULLABLE} ? 1 : 0; |
528
|
2201
|
100
|
|
|
|
6798
|
$column_info->{default_value} = $info->{COLUMN_DEF} if defined $info->{COLUMN_DEF}; |
529
|
2201
|
|
|
|
|
4905
|
my $col_name = $info->{COLUMN_NAME}; |
530
|
2201
|
|
|
|
|
6095
|
$col_name =~ s/^\"(.*)\"$/$1/; |
531
|
|
|
|
|
|
|
|
532
|
2201
|
|
50
|
|
|
7713
|
my $extra_info = $self->_extra_column_info( |
533
|
|
|
|
|
|
|
$table, $col_name, $column_info, $info |
534
|
|
|
|
|
|
|
) || {}; |
535
|
2201
|
|
|
|
|
14183
|
$column_info = { %$column_info, %$extra_info }; |
536
|
|
|
|
|
|
|
|
537
|
2201
|
|
|
|
|
7749
|
$raw_result{$col_name} = $info; |
538
|
2201
|
|
|
|
|
23511
|
$result{$col_name} = $column_info; |
539
|
|
|
|
|
|
|
} |
540
|
778
|
|
|
|
|
28431
|
$sth->finish; |
541
|
|
|
|
|
|
|
} |
542
|
|
|
|
|
|
|
|
543
|
778
|
|
|
|
|
5283
|
my $sth = $self->_sth_for($table, undef, \'1 = 0'); |
544
|
778
|
|
|
|
|
40859
|
$sth->execute; |
545
|
|
|
|
|
|
|
|
546
|
778
|
|
|
|
|
3352
|
my @columns = @{ $sth->{NAME} }; |
|
778
|
|
|
|
|
11236
|
|
547
|
|
|
|
|
|
|
|
548
|
778
|
|
|
|
|
5037
|
COL: for my $i (0 .. $#columns) { |
549
|
2201
|
50
|
|
|
|
3990
|
next COL if %{ $result{ $columns[$i] }||{} }; |
|
2201
|
50
|
|
|
|
10805
|
|
550
|
|
|
|
|
|
|
|
551
|
0
|
|
|
|
|
0
|
my $column_info = {}; |
552
|
0
|
|
|
|
|
0
|
$column_info->{data_type} = lc $sth->{TYPE}[$i]; |
553
|
|
|
|
|
|
|
|
554
|
0
|
|
|
|
|
0
|
my $size = $sth->{PRECISION}[$i]; |
555
|
|
|
|
|
|
|
|
556
|
0
|
0
|
0
|
|
|
0
|
if (defined $size && defined $sth->{SCALE}[$i]) { |
|
|
0
|
|
|
|
|
|
557
|
0
|
|
|
|
|
0
|
$column_info->{size} = [$size, $sth->{SCALE}[$i]]; |
558
|
|
|
|
|
|
|
} |
559
|
|
|
|
|
|
|
elsif (defined $size) { |
560
|
0
|
|
|
|
|
0
|
$column_info->{size} = $size; |
561
|
|
|
|
|
|
|
} |
562
|
|
|
|
|
|
|
|
563
|
0
|
0
|
|
|
|
0
|
$column_info->{is_nullable} = $sth->{NULLABLE}[$i] ? 1 : 0; |
564
|
|
|
|
|
|
|
|
565
|
0
|
0
|
|
|
|
0
|
if ($column_info->{data_type} =~ m/^(.*?)\((.*?)\)$/) { |
566
|
0
|
|
|
|
|
0
|
$column_info->{data_type} = $1; |
567
|
0
|
|
|
|
|
0
|
$column_info->{size} = $2; |
568
|
|
|
|
|
|
|
} |
569
|
|
|
|
|
|
|
|
570
|
0
|
|
0
|
|
|
0
|
my $extra_info = $self->_extra_column_info($table, $columns[$i], $column_info, $sth) || {}; |
571
|
0
|
|
|
|
|
0
|
$column_info = { %$column_info, %$extra_info }; |
572
|
|
|
|
|
|
|
|
573
|
0
|
|
|
|
|
0
|
$result{ $columns[$i] } = $column_info; |
574
|
|
|
|
|
|
|
} |
575
|
778
|
|
|
|
|
4672
|
$sth->finish; |
576
|
|
|
|
|
|
|
|
577
|
778
|
|
|
|
|
3825
|
foreach my $col (keys %result) { |
578
|
2201
|
|
|
|
|
4762
|
my $colinfo = $result{$col}; |
579
|
2201
|
|
|
|
|
4551
|
my $type_num = $colinfo->{data_type}; |
580
|
2201
|
|
|
|
|
3694
|
my $type_name; |
581
|
2201
|
50
|
33
|
|
|
13906
|
if (defined $type_num && $type_num =~ /^-?\d+\z/ && $dbh->can('type_info')) { |
|
|
|
33
|
|
|
|
|
582
|
0
|
|
|
|
|
0
|
my $type_name = $self->_dbh_type_info_type_name($type_num); |
583
|
0
|
0
|
|
|
|
0
|
$colinfo->{data_type} = lc $type_name if $type_name; |
584
|
|
|
|
|
|
|
} |
585
|
|
|
|
|
|
|
} |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
# check for instances of the same column name with different case in preserve_case=0 mode |
588
|
778
|
100
|
|
|
|
4673
|
if (not $self->preserve_case) { |
589
|
306
|
|
|
|
|
933
|
my %lc_colnames; |
590
|
|
|
|
|
|
|
|
591
|
306
|
|
|
|
|
1100
|
foreach my $col (keys %result) { |
592
|
805
|
|
|
|
|
1666
|
push @{ $lc_colnames{lc $col} }, $col; |
|
805
|
|
|
|
|
3208
|
|
593
|
|
|
|
|
|
|
} |
594
|
|
|
|
|
|
|
|
595
|
306
|
50
|
|
|
|
1695
|
if (keys %lc_colnames != keys %result) { |
596
|
0
|
|
|
|
|
0
|
my @offending_colnames = map @$_, grep @$_ > 1, values %lc_colnames; |
597
|
|
|
|
|
|
|
|
598
|
0
|
|
|
|
|
0
|
my $offending_colnames = join ", ", map "'$_'", @offending_colnames; |
599
|
|
|
|
|
|
|
|
600
|
0
|
|
|
|
|
0
|
croak "columns $offending_colnames in table @{[ $table->sql_name ]} collide in preserve_case=0 mode. preserve_case=1 mode required"; |
|
0
|
|
|
|
|
0
|
|
601
|
|
|
|
|
|
|
} |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
# apply lowercasing |
604
|
306
|
|
|
|
|
851
|
my %lc_result; |
605
|
|
|
|
|
|
|
|
606
|
306
|
|
|
|
|
1767
|
while (my ($col, $info) = each %result) { |
607
|
805
|
|
|
|
|
2870
|
$lc_result{ $self->_lc($col) } = $info; |
608
|
|
|
|
|
|
|
} |
609
|
|
|
|
|
|
|
|
610
|
306
|
|
|
|
|
2336
|
%result = %lc_result; |
611
|
|
|
|
|
|
|
} |
612
|
|
|
|
|
|
|
|
613
|
778
|
100
|
|
|
|
42668
|
return wantarray ? (\%result, \%raw_result) : \%result; |
614
|
|
|
|
|
|
|
} |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
# Need to override this for the buggy Firebird ODBC driver. |
617
|
|
|
|
|
|
|
sub _dbh_type_info_type_name { |
618
|
0
|
|
|
0
|
|
0
|
my ($self, $type_num) = @_; |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
# We wrap it in a try block for MSSQL+DBD::Sybase, which can have issues. |
621
|
|
|
|
|
|
|
# TODO investigate further |
622
|
0
|
|
|
0
|
|
0
|
my $type_info = try { $self->dbh->type_info($type_num) }; |
|
0
|
|
|
|
|
0
|
|
623
|
|
|
|
|
|
|
|
624
|
0
|
0
|
|
|
|
0
|
return $type_info ? $type_info->{TYPE_NAME} : undef; |
625
|
|
|
|
|
|
|
} |
626
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
# do not use this, override _columns_info_for instead |
628
|
|
|
|
2201
|
|
|
sub _extra_column_info {} |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
# override to mask warnings if needed |
631
|
|
|
|
|
|
|
sub _dbh_table_info { |
632
|
2314
|
|
|
2314
|
|
246528
|
my ($self, $dbh, $table) = (shift, shift, shift); |
633
|
|
|
|
|
|
|
|
634
|
2314
|
50
|
|
|
|
15736
|
return undef if !$dbh->can('table_info'); |
635
|
2314
|
|
|
|
|
8513
|
my $sth = $dbh->table_info(undef, $table->schema, $table->name); |
636
|
2314
|
|
|
|
|
997252
|
while (my $info = $sth->fetchrow_hashref) { |
637
|
2314
|
50
|
|
|
|
13487
|
next if !$self->_table_info_matches($table, $info); |
638
|
2314
|
|
|
|
|
17402
|
return $info; |
639
|
|
|
|
|
|
|
} |
640
|
0
|
|
|
|
|
0
|
return undef; |
641
|
|
|
|
|
|
|
} |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
sub _table_info_matches { |
644
|
36
|
|
|
36
|
|
115
|
my ($self, $table, $info) = @_; |
645
|
|
|
|
|
|
|
|
646
|
17
|
|
|
17
|
|
178
|
no warnings 'uninitialized'; |
|
17
|
|
|
|
|
39
|
|
|
17
|
|
|
|
|
2872
|
|
647
|
|
|
|
|
|
|
return $info->{TABLE_SCHEM} eq $table->schema |
648
|
36
|
|
33
|
|
|
166
|
&& $info->{TABLE_NAME} eq $table->name; |
649
|
|
|
|
|
|
|
} |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
# override to mask warnings if needed (see mysql) |
652
|
|
|
|
|
|
|
sub _dbh_column_info { |
653
|
2972
|
|
|
2972
|
|
7820
|
my ($self, $dbh) = (shift, shift); |
654
|
|
|
|
|
|
|
|
655
|
2972
|
|
|
|
|
17206
|
return $dbh->column_info(@_); |
656
|
|
|
|
|
|
|
} |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
# If a coderef uses DBI->connect, this should get its connect info. |
659
|
|
|
|
|
|
|
sub _try_infer_connect_info_from_coderef { |
660
|
0
|
|
|
0
|
|
0
|
my ($self, $code) = @_; |
661
|
|
|
|
|
|
|
|
662
|
0
|
|
|
|
|
0
|
my ($dsn, $user, $pass, $params); |
663
|
|
|
|
|
|
|
|
664
|
17
|
|
|
17
|
|
166
|
no warnings 'redefine'; |
|
17
|
|
|
|
|
71
|
|
|
17
|
|
|
|
|
3721
|
|
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
local *DBI::connect = sub { |
667
|
0
|
|
|
0
|
|
0
|
(undef, $dsn, $user, $pass, $params) = @_; |
668
|
0
|
|
|
|
|
0
|
}; |
669
|
|
|
|
|
|
|
|
670
|
0
|
|
|
|
|
0
|
$code->(); |
671
|
|
|
|
|
|
|
|
672
|
0
|
|
|
|
|
0
|
return ($dsn, $user, $pass, $params); |
673
|
|
|
|
|
|
|
} |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
sub dbh { |
676
|
19419
|
|
|
19419
|
0
|
1228382
|
my $self = shift; |
677
|
|
|
|
|
|
|
|
678
|
19419
|
|
|
|
|
574097
|
return $self->schema->storage->dbh; |
679
|
|
|
|
|
|
|
} |
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
sub _table_is_view { |
682
|
778
|
|
|
778
|
|
2501
|
my ($self, $table) = @_; |
683
|
|
|
|
|
|
|
|
684
|
778
|
50
|
|
|
|
2550
|
my $info = $self->_dbh_table_info($self->dbh, $table) |
685
|
|
|
|
|
|
|
or return 0; |
686
|
778
|
|
|
|
|
19205
|
return $info->{TABLE_TYPE} eq 'VIEW'; |
687
|
|
|
|
|
|
|
} |
688
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
=head1 SEE ALSO |
690
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
L |
692
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
=head1 AUTHORS |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
See L. |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
=head1 LICENSE |
698
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
700
|
|
|
|
|
|
|
the same terms as Perl itself. |
701
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
=cut |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
1; |
705
|
|
|
|
|
|
|
# vim:et sts=4 sw=4 tw=0: |