Release 0.07047
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / DBI.pm
CommitLineData
996be9ee 1package DBIx::Class::Schema::Loader::DBI;
2
3use strict;
4use warnings;
abaf2c66 5use base qw/DBIx::Class::Schema::Loader::Base/;
942bd5e0 6use mro 'c3';
61d1cca1 7use Try::Tiny;
ecf22f0a 8use List::Util 'any';
116431d6 9use Carp::Clan qw/^DBIx::Class/;
61d1cca1 10use namespace::clean;
c4a69b87 11use DBIx::Class::Schema::Loader::Table ();
996be9ee 12
306bf770 13our $VERSION = '0.07047';
32f784fc 14
3b17d988 15__PACKAGE__->mk_group_accessors('simple', qw/
16 _disable_pk_detection
17 _disable_uniq_detection
18 _disable_fk_detection
19 _passwords
c4a69b87 20 quote_char
21 name_sep
3b17d988 22/);
23
996be9ee 24=head1 NAME
25
26DBIx::Class::Schema::Loader::DBI - DBIx::Class::Schema::Loader DBI Implementation.
27
28=head1 SYNOPSIS
29
30See L<DBIx::Class::Schema::Loader::Base>
31
32=head1 DESCRIPTION
33
34This is the base class for L<DBIx::Class::Schema::Loader::Base> classes for
35DBI-based storage backends, and implements the common functionality between them.
36
37See L<DBIx::Class::Schema::Loader::Base> for the available options.
38
39=head1 METHODS
40
41=head2 new
42
43Overlays L<DBIx::Class::Schema::Loader::Base/new> to do some DBI-specific
44things.
45
46=cut
47
48sub new {
49 my $self = shift->next::method(@_);
50
71a6e88a 51 # rebless to vendor-specific class if it exists and loads and we're not in a
52 # custom class.
53 if (not $self->loader_class) {
c4a69b87 54 my $driver = $self->dbh->{Driver}->{Name};
71a6e88a 55
56 my $subclass = 'DBIx::Class::Schema::Loader::DBI::' . $driver;
383bd2a8 57 if ((not $self->isa($subclass)) && $self->load_optional_class($subclass)) {
58 bless $self, $subclass;
71a6e88a 59 $self->_rebless;
383bd2a8 60 Class::C3::reinitialize() if $] < 5.009005;
71a6e88a 61 }
996be9ee 62 }
63
dee01f3b 64 # Set up the default quoting character and name separators
c4a69b87 65 $self->quote_char($self->_build_quote_char);
66 $self->name_sep($self->_build_name_sep);
996be9ee 67
68 $self->_setup;
69
383bd2a8 70 return $self;
996be9ee 71}
72
c4a69b87 73sub _build_quote_char {
77d3753e 74 my $self = shift;
c4a69b87 75
76 my $quote_char = $self->dbh->get_info(29)
494e0205 77 || $self->schema->storage->sql_maker->quote_char
78 || q{"};
c4a69b87 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 if (ref $quote_char eq 'ARRAY') {
83 $quote_char = join '', @$quote_char;
84 }
85
86 return $quote_char;
77d3753e 87}
88
c4a69b87 89sub _build_name_sep {
77d3753e 90 my $self = shift;
c4a69b87 91 return $self->dbh->get_info(41)
494e0205 92 || $self->schema->storage->sql_maker->name_sep
93 || '.';
77d3753e 94}
95
996be9ee 96# Override this in vendor modules to do things at the end of ->new()
97sub _setup { }
98
6ae3f335 99# Override this in vendor module to load a subclass if necessary
100sub _rebless { }
101
c4a69b87 102sub _system_schemas {
103 return ('information_schema');
104}
105
106sub _system_tables {
107 return ();
108}
109
110sub _dbh_tables {
36c8c37c 111 my $self = shift;
c4a69b87 112
36c8c37c 113 return $self->dbh->tables(undef, @_);
c4a69b87 114}
115
116# default to be overridden in subclasses if necessary
117sub _supports_db_schema { 1 }
118
119# Returns an array of table objects
a40434df 120sub _tables_list {
5784b2b9 121 my ($self) = @_;
996be9ee 122
c4a69b87 123 my @tables;
124
125 my $qt = qr/[\Q$self->{quote_char}\E"'`\[\]]/;
126 my $nqt = qr/[^\Q$self->{quote_char}\E"'`\[\]]/;
127 my $ns = qr/[\Q$self->{name_sep}\E]/;
128 my $nns = qr/[^\Q$self->{name_sep}\E]/;
129
130 foreach my $schema (@{ $self->db_schema || [undef] }) {
5784b2b9 131 my @raw_table_names = $self->_dbh_tables($schema);
c4a69b87 132
133 TABLE: foreach my $raw_table_name (@raw_table_names) {
134 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 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 my $table_name = $table_name1 || $table_name2;
144
145 foreach my $system_schema ($self->_system_schemas) {
146 if ($schema_name) {
147 my $matches = 0;
148
149 if (ref $system_schema) {
150 $matches = 1
151 if $schema_name =~ $system_schema
494e0205 152 && $schema !~ $system_schema;
c4a69b87 153 }
154 else {
155 $matches = 1
156 if $schema_name eq $system_schema
157 && $schema ne $system_schema;
158 }
159
160 next TABLE if $matches;
161 }
162 }
163
164 foreach my $system_table ($self->_system_tables) {
165 my $matches = 0;
e57fd726 166
c4a69b87 167 if (ref $system_table) {
168 $matches = 1 if $table_name =~ $system_table;
169 }
170 else {
171 $matches = 1 if $table_name eq $system_table
172 }
77d3753e 173
c4a69b87 174 next TABLE if $matches;
175 }
176
177 $schema_name ||= $schema;
385c593b 178
c4a69b87 179 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 );
c5ff1f26 187
c4a69b87 188 push @tables, $table;
189 }
385c593b 190 }
996be9ee 191
5784b2b9 192 return $self->_filter_tables(\@tables);
075aff97 193}
194
b187901e 195sub _recurse_constraint {
196 my ($constraint, @parts) = @_;
197
198 my $name = shift @parts;
199
200 # If there are any parts left, the constraint must be an arrayref
201 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 return $name =~ $constraint unless @parts;
206
207 # recurse into the first matching subconstraint
208 foreach (@{$constraint}) {
209 my ($re, $sub) = @{$_};
210 return _recurse_constraint($sub, @parts)
211 if $name =~ $re;
212 }
213 return 0;
214}
215
216sub _check_constraint {
217 my ($include, $constraint, @tables) = @_;
218
219 return @tables unless defined $constraint;
220
221 return grep { !$include xor _recurse_constraint($constraint, @{$_}) } @tables
222 if ref $constraint eq 'ARRAY';
223
224 return grep { !$include xor /$constraint/ } @tables;
225}
226
227
228
bfb43060 229# apply constraint/exclude and ignore bad tables and views
075aff97 230sub _filter_tables {
5784b2b9 231 my ($self, $tables) = @_;
075aff97 232
bfb43060 233 my @tables = @$tables;
075aff97 234 my @filtered_tables;
235
5784b2b9 236 @tables = _check_constraint(1, $self->constraint, @tables);
237 @tables = _check_constraint(0, $self->exclude, @tables);
bfb43060 238
c4a69b87 239 TABLE: for my $table (@tables) {
61d1cca1 240 try {
afcd3c32 241 local $^W = 0; # for ADO
805dbe0a 242 my $sth = $self->_sth_for($table, undef, \'1 = 0');
243 $sth->execute;
c4a69b87 244 1;
075aff97 245 }
61d1cca1 246 catch {
247 warn "Bad table or view '$table', ignoring: $_\n";
c4a69b87 248 0;
249 } or next TABLE;
61d1cca1 250
251 push @filtered_tables, $table;
075aff97 252 }
253
254 return @filtered_tables;
996be9ee 255}
256
12af3806 257=head2 load
258
259We override L<DBIx::Class::Schema::Loader::Base/load> here to hook in our localized settings for C<$dbh> error handling.
260
261=cut
262
263sub load {
264 my $self = shift;
265
c4a69b87 266 local $self->dbh->{RaiseError} = 1;
267 local $self->dbh->{PrintError} = 0;
12b86f07 268
c4a69b87 269 $self->next::method(@_);
075aff97 270}
271
272sub _sth_for {
273 my ($self, $table, $fields, $where) = @_;
274
c4a69b87 275 my $sth = $self->dbh->prepare($self->schema->storage->sql_maker
4f1bda9c 276 ->select(\$table->sql_name, $fields || \'*', $where));
075aff97 277
278 return $sth;
279}
280
281# Returns an arrayref of column names
282sub _table_columns {
283 my ($self, $table) = @_;
284
285 my $sth = $self->_sth_for($table, undef, \'1 = 0');
996be9ee 286 $sth->execute;
1af21646 287
288 my $retval = [ map $self->_lc($_), @{$sth->{NAME}} ];
289
3b7f80f9 290 $sth->finish;
291
1af21646 292 return $retval;
996be9ee 293}
294
295# Returns arrayref of pk col names
a40434df 296sub _table_pk_info {
fd589700 297 my ($self, $table) = @_;
996be9ee 298
3b17d988 299 return [] if $self->_disable_pk_detection;
300
3b17d988 301 my @primary = try {
c4a69b87 302 $self->dbh->primary_key('', $table->schema, $table->name);
3b17d988 303 }
304 catch {
305 warn "Cannot find primary keys for this driver: $_";
306 $self->_disable_pk_detection(1);
307 return ();
308 };
309
310 return [] if not @primary;
311
312 @primary = map { $self->_lc($_) } @primary;
c4a69b87 313 s/[\Q$self->{quote_char}\E]//g for @primary;
996be9ee 314
315 return \@primary;
316}
317
fd589700 318# Override this for vendor-specific uniq info
996be9ee 319sub _table_uniq_info {
fd589700 320 my ($self, $table) = @_;
321
3b17d988 322 return [] if $self->_disable_uniq_detection;
323
c4a69b87 324 if (not $self->dbh->can('statistics_info')) {
3b17d988 325 warn "No UNIQUE constraint information can be gathered for this driver";
326 $self->_disable_uniq_detection(1);
fd589700 327 return [];
328 }
329
330 my %indices;
c4a69b87 331 my $sth = $self->dbh->statistics_info(undef, $table->schema, $table->name, 1, 1);
fd589700 332 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}
b32f8189 338 || !defined $row->{ORDINAL_POSITION};
fd589700 339
b32f8189 340 $indices{$row->{INDEX_NAME}}[$row->{ORDINAL_POSITION}] = $self->_lc($row->{COLUMN_NAME} || '');
fd589700 341 }
3b7f80f9 342 $sth->finish;
fd589700 343
344 my @retval;
6c4f5a4a 345 foreach my $index_name (sort keys %indices) {
b32f8189 346 my (undef, @cols) = @{$indices{$index_name}};
347 # skip indexes with missing column names (e.g. expression indexes)
348 next unless @cols == grep $_, @cols;
349 push(@retval, [ $index_name => \@cols ]);
fd589700 350 }
351
352 return \@retval;
996be9ee 353}
354
c4a69b87 355sub _table_comment {
356 my ($self, $table) = @_;
7732645c 357 my $dbh = $self->dbh;
5c06aa08 358
b21abfca 359 my $comments_table = $table->clone;
360 $comments_table->name($self->table_comments_table);
5c06aa08 361
07307014 362 my ($comment) =
363 (exists $self->_tables->{$comments_table->sql_name} || undef)
364 && try { $dbh->selectrow_array(<<"EOF") };
c4a69b87 365SELECT comment_text
b21abfca 366FROM @{[ $comments_table->sql_name ]}
7732645c 367WHERE table_name = @{[ $dbh->quote($table->name) ]}
c4a69b87 368EOF
5c06aa08 369
5ffed88c 370 # Failback: try the REMARKS column on table_info
68c6c83f 371 if (!$comment) {
372 my $info = $self->_dbh_table_info( $dbh, $table );
373 $comment = $info->{REMARKS} if $info;
5ffed88c 374 }
375
c4a69b87 376 return $comment;
5c06aa08 377}
378
379sub _column_comment {
b21abfca 380 my ($self, $table, $column_number, $column_name) = @_;
7732645c 381 my $dbh = $self->dbh;
c4a69b87 382
b21abfca 383 my $comments_table = $table->clone;
384 $comments_table->name($self->column_comments_table);
c4a69b87 385
07307014 386 my ($comment) =
387 (exists $self->_tables->{$comments_table->sql_name} || undef)
388 && try { $dbh->selectrow_array(<<"EOF") };
c4a69b87 389SELECT comment_text
b21abfca 390FROM @{[ $comments_table->sql_name ]}
7732645c 391WHERE table_name = @{[ $dbh->quote($table->name) ]}
392AND column_name = @{[ $dbh->quote($column_name) ]}
c4a69b87 393EOF
5ffed88c 394
395 # Failback: try the REMARKS column on column_info
5ffed88c 396 if (!$comment && $dbh->can('column_info')) {
1af21646 397 if (my $sth = try { $self->_dbh_column_info( $dbh, undef, $table->schema, $table->name, $column_name ) }) {
398 my $info = $sth->fetchrow_hashref();
399 $comment = $info->{REMARKS};
400 }
5ffed88c 401 }
402
c4a69b87 403 return $comment;
5c06aa08 404}
405
996be9ee 406# Find relationships
407sub _table_fk_info {
408 my ($self, $table) = @_;
409
3b17d988 410 return [] if $self->_disable_fk_detection;
411
3b17d988 412 my $sth = try {
c4a69b87 413 $self->dbh->foreign_key_info( '', '', '',
414 '', ($table->schema || ''), $table->name );
3b17d988 415 }
416 catch {
417 warn "Cannot introspect relationships for this driver: $_";
418 $self->_disable_fk_detection(1);
419 return undef;
420 };
421
996be9ee 422 return [] if !$sth;
423
424 my %rels;
425
a40434df 426 my @rules = (
427 'CASCADE',
428 'RESTRICT',
429 'SET NULL',
430 'NO ACTION',
431 'SET DEFAULT',
432 );
433
996be9ee 434 my $i = 1; # for unnamed rels, which hopefully have only 1 column ...
c4a69b87 435 REL: while(my $raw_rel = $sth->fetchrow_arrayref) {
436 my $uk_scm = $raw_rel->[1];
996be9ee 437 my $uk_tbl = $raw_rel->[2];
c930f78b 438 my $uk_col = $self->_lc($raw_rel->[3]);
c4a69b87 439 my $fk_scm = $raw_rel->[5];
c930f78b 440 my $fk_col = $self->_lc($raw_rel->[7]);
a273b50c 441 my $key_seq = $raw_rel->[8] - 1;
996be9ee 442 my $relid = ($raw_rel->[11] || ( "__dcsld__" . $i++ ));
c4a69b87 443
a40434df 444 my $update_rule = $raw_rel->[9];
445 my $delete_rule = $raw_rel->[10];
446
447 $update_rule = $rules[$update_rule] if defined $update_rule;
448 $delete_rule = $rules[$delete_rule] if defined $delete_rule;
449
450 my $is_deferrable = $raw_rel->[13];
451
452 ($is_deferrable = $is_deferrable == 7 ? 0 : 1)
453 if defined $is_deferrable;
454
c4a69b87 455 foreach my $var ($uk_scm, $uk_tbl, $uk_col, $fk_scm, $fk_col, $relid) {
ba9954e0 456 $var =~ s/[\Q$self->{quote_char}\E]//g if defined $var;
c4a69b87 457 }
458
459 if ($self->db_schema && $self->db_schema->[0] ne '%'
460 && (not any { $_ eq $uk_scm } @{ $self->db_schema })) {
461
462 next REL;
463 }
464
a40434df 465 $rels{$relid}{tbl} ||= DBIx::Class::Schema::Loader::Table->new(
c4a69b87 466 loader => $self,
467 name => $uk_tbl,
468 schema => $uk_scm,
469 ($self->_supports_db_schema ? () : (
470 ignore_schema => 1
471 )),
472 );
a40434df 473
474 $rels{$relid}{attrs}{on_delete} = $delete_rule if $delete_rule;
475 $rels{$relid}{attrs}{on_update} = $update_rule if $update_rule;
476 $rels{$relid}{attrs}{is_deferrable} = $is_deferrable if defined $is_deferrable;
477
a273b50c 478 # Add this data IN ORDER
479 $rels{$relid}{rcols}[$key_seq] = $uk_col;
480 $rels{$relid}{lcols}[$key_seq] = $fk_col;
996be9ee 481 }
3b7f80f9 482 $sth->finish;
996be9ee 483
484 my @rels;
485 foreach my $relid (keys %rels) {
486 push(@rels, {
79137580 487 remote_columns => [ grep defined, @{ $rels{$relid}{rcols} } ],
488 local_columns => [ grep defined, @{ $rels{$relid}{lcols} } ],
996be9ee 489 remote_table => $rels{$relid}->{tbl},
a40434df 490 (exists $rels{$relid}{attrs} ?
491 (attrs => $rels{$relid}{attrs})
492 :
493 ()
494 ),
495 _constraint_name => $relid,
996be9ee 496 });
497 }
498
499 return \@rels;
500}
501
12af3806 502# ported in from DBIx::Class::Storage::DBI:
503sub _columns_info_for {
504 my ($self, $table) = @_;
505
506 my $dbh = $self->schema->storage->dbh;
507
61d1cca1 508 my %result;
509
1af21646 510 if (my $sth = try { $self->_dbh_column_info($dbh, undef, $table->schema, $table->name, '%' ) }) {
511 COL_INFO: while (my $info = try { $sth->fetchrow_hashref } catch { +{} }) {
512 next COL_INFO unless %$info;
513
61d1cca1 514 my $column_info = {};
515 $column_info->{data_type} = lc $info->{TYPE_NAME};
516
517 my $size = $info->{COLUMN_SIZE};
518
519 if (defined $size && defined $info->{DECIMAL_DIGITS}) {
520 $column_info->{size} = [$size, $info->{DECIMAL_DIGITS}];
12af3806 521 }
61d1cca1 522 elsif (defined $size) {
523 $column_info->{size} = $size;
524 }
525
526 $column_info->{is_nullable} = $info->{NULLABLE} ? 1 : 0;
527 $column_info->{default_value} = $info->{COLUMN_DEF} if defined $info->{COLUMN_DEF};
528 my $col_name = $info->{COLUMN_NAME};
529 $col_name =~ s/^\"(.*)\"$/$1/;
530
61d1cca1 531 my $extra_info = $self->_extra_column_info(
532 $table, $col_name, $column_info, $info
533 ) || {};
534 $column_info = { %$column_info, %$extra_info };
535
536 $result{$col_name} = $column_info;
537 }
538 $sth->finish;
12af3806 539 }
540
075aff97 541 my $sth = $self->_sth_for($table, undef, \'1 = 0');
12af3806 542 $sth->execute;
61d1cca1 543
ed18888f 544 my @columns = @{ $sth->{NAME} };
61d1cca1 545
1af21646 546 COL: for my $i (0 .. $#columns) {
22f91663 547 next COL if %{ $result{ $columns[$i] }||{} };
1af21646 548
23d1f36b 549 my $column_info = {};
57a9fc92 550 $column_info->{data_type} = lc $sth->{TYPE}[$i];
26334ec1 551
552 my $size = $sth->{PRECISION}[$i];
553
554 if (defined $size && defined $sth->{SCALE}[$i]) {
555 $column_info->{size} = [$size, $sth->{SCALE}[$i]];
556 }
557 elsif (defined $size) {
558 $column_info->{size} = $size;
559 }
560
57a9fc92 561 $column_info->{is_nullable} = $sth->{NULLABLE}[$i] ? 1 : 0;
23d1f36b 562
563 if ($column_info->{data_type} =~ m/^(.*?)\((.*?)\)$/) {
564 $column_info->{data_type} = $1;
565 $column_info->{size} = $2;
12af3806 566 }
567
698c11d8 568 my $extra_info = $self->_extra_column_info($table, $columns[$i], $column_info, $sth) || {};
23d1f36b 569 $column_info = { %$column_info, %$extra_info };
570
116431d6 571 $result{ $columns[$i] } = $column_info;
12af3806 572 }
6ce0bcc3 573 $sth->finish;
574
575 foreach my $col (keys %result) {
576 my $colinfo = $result{$col};
577 my $type_num = $colinfo->{data_type};
578 my $type_name;
afcd3c32 579 if (defined $type_num && $type_num =~ /^-?\d+\z/ && $dbh->can('type_info')) {
5111e5d0 580 my $type_name = $self->_dbh_type_info_type_name($type_num);
cf0ba25b 581 $colinfo->{data_type} = lc $type_name if $type_name;
6ce0bcc3 582 }
583 }
12af3806 584
116431d6 585 # check for instances of the same column name with different case in preserve_case=0 mode
586 if (not $self->preserve_case) {
587 my %lc_colnames;
588
589 foreach my $col (keys %result) {
590 push @{ $lc_colnames{lc $col} }, $col;
591 }
592
593 if (keys %lc_colnames != keys %result) {
594 my @offending_colnames = map @$_, grep @$_ > 1, values %lc_colnames;
595
596 my $offending_colnames = join ", ", map "'$_'", @offending_colnames;
597
598 croak "columns $offending_colnames in table @{[ $table->sql_name ]} collide in preserve_case=0 mode. preserve_case=1 mode required";
599 }
600
601 # apply lowercasing
602 my %lc_result;
603
604 while (my ($col, $info) = each %result) {
605 $lc_result{ $self->_lc($col) } = $info;
606 }
607
608 %result = %lc_result;
609 }
610
12af3806 611 return \%result;
612}
613
23024b3f 614# Need to override this for the buggy Firebird ODBC driver.
5111e5d0 615sub _dbh_type_info_type_name {
23024b3f 616 my ($self, $type_num) = @_;
617
354b6942 618 # We wrap it in a try block for MSSQL+DBD::Sybase, which can have issues.
619 # TODO investigate further
620 my $type_info = try { $self->dbh->type_info($type_num) };
a40434df 621
5111e5d0 622 return $type_info ? $type_info->{TYPE_NAME} : undef;
23024b3f 623}
624
db9c411a 625# do not use this, override _columns_info_for instead
a8df0345 626sub _extra_column_info {}
c5baf131 627
5ffed88c 628# override to mask warnings if needed
629sub _dbh_table_info {
68c6c83f 630 my ($self, $dbh, $table) = (shift, shift, shift);
631
632 return undef if !$dbh->can('table_info');
633 my $sth = $dbh->table_info(undef, $table->schema, $table->name);
634 while (my $info = $sth->fetchrow_hashref) {
635 next if !$self->_table_info_matches($table, $info);
636 return $info;
637 }
638 return undef;
639}
640
641sub _table_info_matches {
642 my ($self, $table, $info) = @_;
5ffed88c 643
68c6c83f 644 no warnings 'uninitialized';
645 return $info->{TABLE_SCHEM} eq $table->schema
646 && $info->{TABLE_NAME} eq $table->name;
5ffed88c 647}
648
db9c411a 649# override to mask warnings if needed (see mysql)
650sub _dbh_column_info {
651 my ($self, $dbh) = (shift, shift);
652
653 return $dbh->column_info(@_);
654}
655
3b17d988 656# If a coderef uses DBI->connect, this should get its connect info.
657sub _try_infer_connect_info_from_coderef {
658 my ($self, $code) = @_;
659
660 my ($dsn, $user, $pass, $params);
661
662 no warnings 'redefine';
663
664 local *DBI::connect = sub {
665 (undef, $dsn, $user, $pass, $params) = @_;
666 };
667
668 $code->();
669
670 return ($dsn, $user, $pass, $params);
671}
672
c4a69b87 673sub dbh {
674 my $self = shift;
675
676 return $self->schema->storage->dbh;
677}
678
ce2f102a 679sub _table_is_view {
680 my ($self, $table) = @_;
681
682 my $info = $self->_dbh_table_info($self->dbh, $table)
683 or return 0;
684 return $info->{TABLE_TYPE} eq 'VIEW';
685}
686
996be9ee 687=head1 SEE ALSO
688
689L<DBIx::Class::Schema::Loader>
690
b87ab391 691=head1 AUTHORS
be80bba7 692
b87ab391 693See L<DBIx::Class::Schema::Loader/AUTHORS>.
be80bba7 694
695=head1 LICENSE
696
697This library is free software; you can redistribute it and/or modify it under
698the same terms as Perl itself.
699
996be9ee 700=cut
701
7021;
26334ec1 703# vim:et sts=4 sw=4 tw=0: