}
s/$qt//g for @tables;
- return @tables;
+ return $self->_filter_tables(@tables);
+}
+
+# ignore bad tables and views
+sub _filter_tables {
+ my ($self, @tables) = @_;
+
+ my @filtered_tables;
+
+ for my $table (@tables) {
+ my $sth = $self->_sth_for($table, undef, \'1 = 0');
+ eval { $sth->execute };
+ if (not $@) {
+ push @filtered_tables, $table;
+ }
+ else {
+ warn "Bad table or view '$table', ignoring: $@\n";
+ }
+ }
+
+ return @filtered_tables;
}
=head2 load
$self->next::method(@_);
}
-# Returns an arrayref of column names
-sub _table_columns {
+sub _table_as_sql {
my ($self, $table) = @_;
- my $dbh = $self->schema->storage->dbh;
-
if($self->{db_schema}) {
$table = $self->{db_schema} . $self->{_namesep} .
$self->_quote_table_name($table);
$table = $self->_quote_table_name($table);
}
- my $sth = $dbh->prepare($self->schema->storage->sql_maker->select(\$table, undef, \'1 = 0'));
+ return $table;
+}
+
+sub _sth_for {
+ my ($self, $table, $fields, $where) = @_;
+
+ my $dbh = $self->schema->storage->dbh;
+
+ my $sth = $dbh->prepare($self->schema->storage->sql_maker
+ ->select(\$self->_table_as_sql($table), $fields, $where));
+
+ return $sth;
+}
+
+# Returns an arrayref of column names
+sub _table_columns {
+ my ($self, $table) = @_;
+
+ my $sth = $self->_sth_for($table, undef, \'1 = 0');
$sth->execute;
my $retval = \@{$sth->{NAME_lc}};
$sth->finish;
return \%result if !$@ && scalar keys %result;
}
- if($self->db_schema) {
- $table = $self->db_schema . $self->{_namesep} . $table;
- }
my %result;
- my $sth = $dbh->prepare($self->schema->storage->sql_maker->select($table, undef, \'1 = 0'));
+ my $sth = $self->_sth_for($table, undef, \'1 = 0');
$sth->execute;
my @columns = @{$sth->{NAME_lc}};
for my $i ( 0 .. $#columns ){
$self->_set_quote_char_and_name_sep;
}
-# drop bad tables when constructing list
-sub _tables_list {
- my $self = shift;
-
- my @tables = $self->next::method(@_);
- my @filtered_tables;
-
- for my $table (@tables) {
- my $full_quoted_table;
- if($self->{db_schema}) {
- $full_quoted_table = $self->{db_schema} . $self->{_namesep} .
- $self->_quote_table_name($table);
- } else {
- $full_quoted_table = $self->_quote_table_name($table);
- }
- my $dbh = $self->schema->storage->dbh;
- my $sth = $dbh->prepare($self->schema->storage->sql_maker
- ->select(\$full_quoted_table, undef, \'1 = 0'));
- eval { $sth->execute };
- if (not $@) {
- push @filtered_tables, $table;
- }
- else {
- warn "Bad table or view '$table', ignoring.\n";
- }
- }
-
- return @filtered_tables;
-}
-
# remove 'IDENTITY' from column data_type
sub _columns_info_for {
my $self = shift;
}
}
-
-sub _table_columns {
+sub _table_as_sql {
my ($self, $table) = @_;
- my $dbh = $self->schema->storage->dbh;
-
- my $sth = $dbh->prepare($self->schema->storage->sql_maker->select($table, undef, \'1 = 0'));
- $sth->execute;
- return \@{$sth->{NAME_lc}};
+ return $self->_quote_table_name($table);
}
sub _tables_list {
push @tables, $1
if $table =~ /\A(\w+)\z/;
}
- return @tables;
+ return $self->_filter_tables(@tables);
}
sub _table_uniq_info {
my $dbh = $self->schema->storage->dbh;
my @tables = $dbh->tables(undef, $self->db_schema, $table, $type);
- return @tables;
+ return $self->_filter_tables(@tables);
}
=head1 SEE ALSO
if(!exists($self->{_cache}->{_mysql_keys}->{$table})) {
my %keydata;
my $dbh = $self->schema->storage->dbh;
- my $sth = $dbh->prepare("SHOW INDEX FROM `$table`");
+ my $sth = $dbh->prepare('SHOW INDEX FROM '.$self->_table_as_sql($table));
$sth->execute;
while(my $row = $sth->fetchrow_hashref) {
next if $row->{Non_unique};
my $warn_count = 0;
$warn_count++ if grep /ResultSetManager/, @loader_warnings;
$warn_count++ if grep /Dynamic schema detected/, @loader_warnings;
+ $warn_count++ for grep /^Bad table or view/, @loader_warnings;
if($self->{skip_rels}) {
is(scalar(@loader_warnings), $warn_count)
my $warn_count = 2;
$warn_count++ if grep /ResultSetManager/, @loader_warnings;
+ $warn_count++ for grep /^Bad table or view/, @loader_warnings;
+
if($self->{skip_rels}) {
SKIP: {
is(scalar(@loader_warnings), $warn_count, "No loader warnings")