ugly hack to ignore bad tables for ODBC/MSSQL
Rafael Kitover [Mon, 4 Jan 2010 11:14:20 +0000 (11:14 +0000)]
lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm

index ca55379..5007cbe 100644 (file)
@@ -38,6 +38,36 @@ sub _setup {
     $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;