}
else {
warn "Bad table or view '$table', ignoring: $@\n";
+ local $@;
+ eval {
+ my $schema = $self->schema;
+ # in older DBIC it's a private method
+ my $unregister = $schema->can('unregister_source')
+ || $schema->can('_unregister_source');
+ $schema->$unregister($self->_table2moniker($table));
+ };
}
}
foreach my $source_name ($schema->sources) {
my $table_name = $schema->source($source_name)->from;
$monikers{$table_name} = $source_name;
- $classes{$table_name} = "${SCHEMA_CLASS}::" . (
- $loader_opts{use_namespaces} ? 'Result::' : '') . $source_name;
+ $classes{$table_name} = $schema->source($source_name)->result_class;
}
return {
my $expected_count = 34;
- $expected_count += @{ $self->{extra}{drop} || [] };
+ $expected_count += @{ $self->{extra}{create} || [] };
$expected_count -= grep /CREATE TABLE/, @statements_inline_rels
if $self->{no_inline_rels};
$warn_count++ for grep /^Bad table or view/, @loader_warnings;
+ my $vendor = $self->{vendor};
+ $warn_count++ for grep /${vendor}_\S+ has no primary key/,
+ @loader_warnings;
+
if($self->{skip_rels}) {
SKIP: {
is(scalar(@loader_warnings), $warn_count, "No loader warnings")
package dbixcsl_mssql_extra_tests;
use Test::More;
+use Test::Exception;
my $vendor = 'mssql';
$vendor = shift;
}
+# for cleanup in END
+my $saved_dbh;
+
sub extra { +{
create => [
qq{
ts DATETIME DEFAULT getdate()
)
},
+ qq{
+ CREATE TABLE ${vendor}_loader_test3 (
+ id INT IDENTITY NOT NULL PRIMARY KEY
+ )
+ },
+ qq{
+ CREATE VIEW ${vendor}_loader_test4 AS
+ SELECT * FROM ${vendor}_loader_test3
+ },
+ ],
+ drop => [
+ "[${vendor}_loader_test1.dot]",
+ "${vendor}_loader_test2",
+ "${vendor}_loader_test3"
],
- drop => [ "[${vendor}_loader_test1.dot]", "${vendor}_loader_test2" ],
- count => 13,
+ count => 15,
run => sub {
my ($schema, $monikers, $classes) = @_;
is $identity_col_info->{is_auto_increment}, 1,
q{'INT IDENTITY' column has is_auto_increment => 1};
+
+# Test that a bad view (where underlying table is gone) is ignored.
+ $saved_dbh = $schema->storage->dbh;
+ $saved_dbh->do("DROP TABLE ${vendor}_loader_test3");
+
+ my @warnings;
+ {
+ local $SIG{__WARN__} = sub { push @warnings, $_[0] };
+ $schema->rescan;
+ }
+ ok ((grep /^Bad table or view '${vendor}_loader_test4'/, @warnings),
+ 'bad view ignored');
+
+ throws_ok {
+ $schema->resultset("${vendor_titlecased}LoaderTest4")
+ } qr/Can't find source/,
+ 'no source registered for bad view';
},
}}
+# Clean up the bad view, table will be cleaned up in drops
+END {
+ local $@;
+ eval {
+ $saved_dbh->do($_) for (
+"CREATE TABLE ${vendor}_loader_test3 (id INT IDENTITY NOT NULL PRIMARY KEY)",
+"DROP VIEW ${vendor}_loader_test4"
+ );
+ };
+}
+
1;